Skip to content

Instantly share code, notes, and snippets.

@erdum
Created January 29, 2024 07:41
Show Gist options
  • Save erdum/3aa029e88f2d586c6ec20e1dde3b6d0a to your computer and use it in GitHub Desktop.
Save erdum/3aa029e88f2d586c6ec20e1dde3b6d0a to your computer and use it in GitHub Desktop.
Python IP scanner
import socket
def check_port(ip, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((ip, port))
sock.close()
return result == 0
def scan_ports(start_ip, end_ip, port):
for i in range(start_ip, end_ip + 1):
# Replace with your network range
ip = f'192.168.18.{i}'
print(f'Testing port host {ip}...')
if check_port(ip, port):
print(f'IP Address {ip} is allowing connection on port {port}')
if __name__ == "__main__":
start_ip = 1
end_ip = 255
# Replace with your required port
target_port = 4370
scan_ports(start_ip, end_ip, target_port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment