Right now I’m brushing up on my Python, as well as learning about firewalls. I’m currenly working with an opensource firewall utility thats available on many routers, called pfSense. So far I’ve been using a book called, pfSense: The Definitive Guide
In the course of learning some of the basics of firewalls, I thought I’d investigate Python’s native abilities on the topic, available by importing the Socket library.
Scanner.py - Code for returning active ports
1234567891011121314151617181920
importsocketdefretBanner(ip,port):try:socket.setdefaulttimeout(2)s=socket.socket()s.connect((ip,port))banner=s.recv(1024)returnbannerexcept:returndefmain():iplist=[66]# IP address of my raspberry piforxiniplist:# Could be range, instead of listip='192.168.11.'+str(x)forportinrange(1,35000):# Defines Port Rangebanner=retBanner(ip,port)ifbanner:# [+] Errorhandling; printing active portsprint'[+] '+ip+':'+str(port)+' - '+bannerif__name__=='__main__':main()
Results
123
## Results ##
$[+] 192.168.11.66:SSH-2.0-OpenSSH_6.1p1 Debian-4 # SSH Server
$[+] 192.168.11.66:RFB 003.007 # VNC server