Last active
May 26, 2018 07:04
-
-
Save darrena092/bf7844d9ea66143b6785c7d5ad7ac6c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ipaddress | |
import os | |
import socket | |
import threading | |
import sys | |
network = ipaddress.ip_network('192.168.1.0/24') | |
def scanport(host, port_number): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.settimeout(5) | |
if sock.connect_ex((host, port_number)) == 0: | |
print("\t Port " + str(port_number) + " open.\033[K") | |
# Find hosts that are up and scan them. | |
scanning_threads = [] | |
for host in network.hosts(): | |
if os.system('ping -n 1 -w 10 ' + str(host) + ' >nul') == 0: | |
print("Host is up at: " + str(host)) | |
print("Scanning host...") | |
for port in range(1, 65535): | |
scan_thread = threading.Thread(target=scanport, args=(str(host), port)) | |
scan_thread.start() | |
scanning_threads.append(scan_thread) | |
if((port % 100) == 0): | |
# Wait for all current threads to finish. | |
for thread in scanning_threads: | |
thread.join() | |
# All threads are finished, we can clear the buffer. | |
scanning_threads.clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment