Find Open Port(s) on Address(es)
So, I was trying to find out which PC on a network (which I was VPN’d into) had VNC running on it. NetBIOS wasn’t working, so I couldn’t access the PC by name. All the tools that I found just didn’t work properly for doing a port scan on a range of addresses over VPN. So, I threw together a portscanner in Python (v2.6.6) really fast.
from socket import *
fTimeOutSec = 1.1
sNetworkAddress = '192.168.1'
aiHostAddresses = range(1,255)
aiPorts = [5900]
setdefaulttimeout(fTimeOutSec)
print "Starting Scan..."
for h in aiHostAddresses:
for p in aiPorts:
s = socket(AF_INET, SOCK_STREAM)
address = ('%s.%d' % (sNetworkAddress, h))
result = s.connect_ex((address,p))
if ( 0 == result ):
print "%s:%d - OPEN" % (address,p)
elif ( 10035 == result ):
#do nothing, was a timeout, probably host doesn't exist
pass
else:
print "%s:%d - closed (%d)" % (address,p,result)
s.close()
print "Scan Completed."
Comments
Leave a Reply
You must be logged in to post a comment.