added ping subprocess
This commit is contained in:
parent
1e840001f5
commit
1dbc78e4de
23
scan.py
23
scan.py
@ -1,6 +1,8 @@
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
from ping3 import ping
|
from ping3 import ping
|
||||||
import socket
|
import socket
|
||||||
|
import time
|
||||||
|
import subprocess as sp
|
||||||
|
|
||||||
def get_ip():
|
def get_ip():
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
@ -16,12 +18,29 @@ def get_ip():
|
|||||||
return IP
|
return IP
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("IP:", get_ip())
|
ip = get_ip()
|
||||||
|
print("IP:", ip)
|
||||||
|
try:
|
||||||
|
ping(ip, timeout=1)
|
||||||
|
except:
|
||||||
|
print("could not ping self")
|
||||||
|
try:
|
||||||
|
r = sp.run(['ping', '-c', '4', ip])
|
||||||
|
print(r.returncode)
|
||||||
|
except:
|
||||||
|
print("ping command not available")
|
||||||
|
|
||||||
network = ipaddress.ip_network('192.168.1.0/24') # Creates subnet object
|
network = ipaddress.ip_network('192.168.1.0/24') # Creates subnet object
|
||||||
for ip in network:
|
for ip in network:
|
||||||
|
try:
|
||||||
p = ping(str(ip), timeout=1)
|
p = ping(str(ip), timeout=1)
|
||||||
if p is not None:
|
if p is not None:
|
||||||
print("Found host at:", ip)
|
print("Found host at:", ip)
|
||||||
|
except:
|
||||||
|
r = sp.run(['ping', '-c', '4', ip])
|
||||||
|
if r.returncode == 0:
|
||||||
|
print("Found host at:", ip)
|
||||||
|
|
||||||
print("DONE")
|
print("DONE")
|
||||||
while True:
|
while True:
|
||||||
pass
|
time.sleep(10)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user