Junior — Middle
What methods of network device scanning are you familiar with?
sobes.tech AI
Answer from AI
Main methods of scanning network devices that can be used with Python:
- Ping scanning — checking device availability via ICMP requests.
- TCP port scanning — attempting to establish TCP connections on specific ports to identify open services.
- UDP scanning — sending UDP packets to detect open UDP ports.
- ARP scanning — identifying devices on a local network via ARP requests.
- SNMP scanning — retrieving information from devices supporting SNMP.
Common libraries used for implementation:
scapy— for creating and sending various types of packets.socket— for low-level network connection handling.python-nmap— a wrapper for nmap, a powerful scanning tool.
Example of a simple TCP scanner in Python:
import socket
def scan_port(ip, port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(1)
try:
s.connect((ip, port))
return True
except:
return False
ip = '192.168.1.1'
ports = [22, 80, 443]
for port in ports:
if scan_port(ip, port):
print(f"Port {port} is open")
else:
print(f"Port {port} is closed")