Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ipaddress
- from threading import Thread
- import socket
- import subprocess
- def check_Open(ip):
- # print(type((ip)))
- try:
- port_num = 60000
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.settimeout(5)
- result = sock.connect_ex((str(ip), port_num))
- if result == 0:
- print(f'IP {ip} is open')
- except Exception as err:
- print(err)
- sock.close()
- finally:
- sock.close()
- def checkUP(ip):
- ping_result = subprocess.run(['ping','-c','1', str(ip)], stdout=subprocess.PIPE)
- if ping_result.returncode == 0:
- print(f'IP is up: {ip}')
- if __name__ == "__main__":
- start_ip = ipaddress.IPv4Address('192.168.0.0')
- end_ip = ipaddress.IPv4Address('192.168.1.255')
- for ip in range(int(start_ip), int(end_ip)+1):
- # print(ipaddress.IPv4Address(ip))
- th = Thread(target=check_Open,args=(ipaddress.IPv4Address(ip),))
- th.start()
- th2 = Thread(target=checkUP,args=(ipaddress.IPv4Address(ip),))
- th2.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement