Недавно я столкнулся с проблемой, связанной с запуском программы python на linux. Я написал сканер IP для локальной сети (как и arp-scan), который отлично работает на windows, но выдает ошибку (см. Ниже) при выполнении программы в оболочке linux (fedora). Якобы эта проблема связана с многопоточностью или tcp? Я также проверил версию python, которая точно такая же в Fedora и windows (3.7). Кроме того, в сообщении об ошибке говорится: «сеть недоступна», хотя сеть работает на все сто процентов (youtube, github ...)
Эта проблема сводит меня с ума, может ли кто-нибудь помочь?
In ниже вы можете найти код и данную ошибку.
ошибка
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/liveuser/Coding/python_stuff/ipscanner_network/thread.py", line 21, in process
client_socket.connect((current_ip, 5555))
OSError: [Errno 101] Network is unreachable
Exception in thread Thread-19:
Exception in thread Thread-79:
Exception in thread Thread-23:
Traceback (most recent call last):
Exception in thread Thread-42:
Traceback (most recent call last):
Exception in thread Thread-69:
Exception in thread Thread-46:
Traceback (most recent call last):
Exception in thread Thread-39:
Traceback (most recent call last):
Exception in thread Thread-34:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-37:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-57:
Exception in thread Thread-54:
Traceback (most recent call last):
Exception in thread Thread-4:
Exception in thread Thread-71:
Exception in thread Thread-31:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-32:
Exception in thread Thread-48:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-243:
Exception in thread Thread-232:
Exception in thread Thread-240:
Traceback (most recent call last):
Exception in thread Thread-233:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-199:
Traceback (most recent call last):
Exception in thread Thread-247:
Traceback (most recent call last):
Exception in thread Thread-246:
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-64:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-215:
Traceback (most recent call last):
Exception in thread Thread-168:
Exception in thread Thread-236:
Exception in thread Thread-110:
Traceback (most recent call last):
Exception in thread Thread-202:
Exception in thread Thread-204:
Exception in thread Thread-125:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-220:
Traceback (most recent call last):
Exception in thread Thread-198:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-235:
Exception in thread Thread-201:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-74:
Traceback (most recent call last):
Exception in thread Thread-8:
Traceback (most recent call last):
File "/usr/lib64/python3.8/threading.py", line 932, in _bootstrap_inner
Exception in thread Thread-14:
... few more lines, didn't fit in anymore
ip_scanner.py
import thread
import socket
import vals
for i in range(vals.number_of_threads):
x = thread.thread(i)
x.start()
while True:
if not("running" in vals.threads_status):
for i in vals.available_ips:
try:
hostname = gethostbyaddr(i)
except:
hostname = "-"
print("[ " + i + " ] " + hostname)
break
thread.py
import threading
import socket
import vals
class thread(threading.Thread):
def __init__(self, number):
threading.Thread.__init__(self, target = self.process, args=[])
self.number = number
vals.threads_status[self.number] = "running"
def process(self):
while True:
iterate = vals.iterate
if iterate<255:
vals.iterate+=1
current_ip = vals.ip_pre + str(iterate)
#print("Now at " + current_ip + "\n")
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.settimeout(vals.timeout)
client_socket.connect((current_ip, 5555))
client_socket.close()
#print("Available IP found: " + current_ip + "\n")
vals.available_ips.append(current_ip)
except ConnectionRefusedError:
client_socket.close()
#print("Available IP found: " + current_ip + "\n")
vals.available_ips.append(current_ip)
except socket.timeout:
#print("Tried " + current_ip + " ==> no success\n")
client_socket.close()
else:
vals.threads_status[self.number] = "terminated"
break
vals.py
ip_pre = "192.168.178."
number_of_threads = 256
iterate = 0
timeout = 4
available_ips = []
threads_status = []
for i in range(number_of_threads):
threads_status.append("")