# Import necessary modules
from scapy.all import *
# Parse and create IP range
octets = input_string.split('.')
chunks = [map(int, octet.split('-')) for octet in octets]
ranges = [range(c, c + 1) if len(c) == 2 else c for c in chunks]
for address in itertools.product(*ranges):
yield '.'.join(map(str, address))
# Scan each IP address with the identified port number
for i in ip_range(ips):
src_port = RandShort()
dst_port = port
scan = sr1(IP(dst=i)/TCP(sport=src_port,dport=dst_port,flags="S"),timeout=10)
if scan is None:
print "This port is closed on IP: " + i
print "This port is open for IP: " + i
print "Unknown state"
# Request port number from user
port = int(raw_input('Enter which port to scan --> '))
# Request IP range from user - form should follow this format '192.168.1.1-26'
ips = raw_input('Enter your range using this format x.x.x.x-x --> ')
Wednesday, December 11, 2013
Python & Scapy - Simple port scanner
I have been learning more about python and taking some courses with the Pentester Academy. One of the projects is to create a simple port scanner using scapy. The next iteration will incorporate threading. Hopefully you find this interesting and see the value of Python and Scapy! Comments, suggestions, observations encouraged. Enjoy!