In cybersecurity, a port scanner is a fundamental tool used to discover open entry points on a network system. While most people use a computer, you can actually build and run a functional network scanner right on your smartphone using a Linux environment.
Since Python is a powerful language for security automation, we can combine it with Termux to scan network targets on the go.
Prerequisites
To follow along with this tutorial on your mobile device, you only need:
- Termux app installed on your phone.
- Python and a text editor installed via the command:
pkg install python nano -y
The Python Script (scanner.py)
Here is the clean script that utilizes Python's built-in socket library to attempt network connections on standard ports:
import socket
target = "scanme.nmap.org"
ports_to_scan = [22, 80, 443]
print(f"Starting basic mobile scan on target: {target}\n")
for port in ports_to_scan:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2.0)
result = s.connect_ex((target, port))
if result == 0:
print(f"[+] Port {port} is OPEN!")
else:
print(f"[-] Port {port} is closed.")
s.close()
How It Works
- socket.socket: Creates a network endpoint to communicate.
- s.settimeout(2.0): Prevents the script from hanging forever if a port is tightly secured or filtered.
-
s.connect_ex: Attempts the connection. If it returns a value of
0, the connection succeeded, meaning the port is listening (OPEN).
Running the Scan on Mobile
Once saved inside your Termux terminal via nano scanner.py, run the tool using:
python scanner.py
This gives you a powerful, portable tool to quickly assess a domain's basic web setup right from your pocket!
Top comments (0)