Advertisement
MrdodgerX

PortScanner

Mar 22nd, 2023 (edited)
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | Source Code | 0 0
  1. import ipaddress
  2. from threading import Thread
  3. import socket
  4. import subprocess
  5.  
  6. def check_Open(ip):
  7.     # print(type((ip)))
  8.     try:
  9.         port_num = 60000
  10.         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  11.         sock.settimeout(5)
  12.    
  13.         result = sock.connect_ex((str(ip), port_num))
  14.         if result == 0:
  15.             print(f'IP {ip} is open')
  16.     except Exception as err:
  17.         print(err)
  18.         sock.close()
  19.     finally:
  20.         sock.close()
  21.  
  22. def checkUP(ip):
  23.     ping_result = subprocess.run(['ping','-c','1', str(ip)], stdout=subprocess.PIPE)
  24.     if ping_result.returncode == 0:
  25.         print(f'IP is up: {ip}')
  26.  
  27. if __name__ == "__main__":
  28.     start_ip = ipaddress.IPv4Address('192.168.0.0')
  29.     end_ip = ipaddress.IPv4Address('192.168.1.255')
  30.  
  31.     for ip in range(int(start_ip), int(end_ip)+1):
  32.         # print(ipaddress.IPv4Address(ip))
  33.         th = Thread(target=check_Open,args=(ipaddress.IPv4Address(ip),))
  34.         th.start()
  35.         th2 = Thread(target=checkUP,args=(ipaddress.IPv4Address(ip),))
  36.         th2.start()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement