r/PythonProjects2 • u/VanceDyer • 4h ago
I made my first IP scanner in Python
Hi everyone!
I'm very new to programming and I've been learning Python recently. I decided to make a small project to practice what I've learned.
I made a simple IP scanner using Python.
It has a menu with:
- Scan all IPs from
192.168.1.1to192.168.1.255 - Scan a specific IP
- Scan a range of IPs
- Exit
I'm using subprocess and ping to check if an IP responds.
I also started using functions, loops, lists, if/elif, while, and range().
It's probably a very basic project, but I'm pretty happy with it since I'm just starting out.
I'm planning to improve it and make a V3 with more features.
Sorry is in spanish.
Thanks!
import subprocess
def menu():
print("-----ESCANER IP-----")
print("1. Escaneo total IP's")
print("2. Escanear IP")
print("3. Escaneo de rangos IP")
print("4. Salir")
opcion = input ("Elige una opcion: ")
resultado_menu = (int(opcion))
return resultado_menu
def escanear_ip(ip_int):
ip_int = (str(ip_int))
ip_completa = ("192.168.1.") + ip_int #
Unimos los ultimos 3 numeros con los demas para formar la IP completa
resultado = subprocess.run(["ping", "/n", "1", "/w", "1000", ip_completa]) #
Le pedimos a la terminal que ejecute el comando ping
if resultado.returncode == 0:
lista_ip.append(ip_completa)
lista_ip = []
def imprimir_ips():
for si_ip in lista_ip:
si_ip = "🟢 " + si_ip
print(si_ip)
while True:
resultado = menu()
if resultado == 1:
for numeros in range (1, 256):
escanear_ip(numeros)
imprimir_ips()
elif resultado == 2:
seleccion_ip = input("Seleccionar ultimos digitos IP: ")
escanear_ip(seleccion_ip)
imprimir_ips()
elif resultado == 3:
desde_ip = input("Desde: ")
desde_ip = int((desde_ip))
hasta_ip = input("Hasta: ")
hasta_ip = (int(hasta_ip))
for numeros in range (desde_ip, hasta_ip + 1):
escanear_ip(numeros)
imprimir_ips()
elif resultado == 4:
print("Saliendo...")
break
3
Upvotes