I'm new to python and socket programming, and trying to scan a port of a WAN address.
I know from using nmap that he has port 80 and 443 open.
Why can't I read from it to see if it's open??? Also, when I scan my gateway with my program it shows that 21 and 23 are open which is what NMAP shows me. BUT nmap also tells me I have port 80 and 443 as well, yet my program doesn't pick those up.
Thanks
def return_banner(ip, port):
try:
socket.setdefaulttimeout(2)
s = socket.socket()
s.connect((ip, port)) #establish connection
banner = s.recv(1024) #receive the first 1024 bytes from socket
return banner
except:
return #will return none
def main():
lan_or_wan()
dictionary_of_open_services = {}
list_of_ports = [20, 21, 22, 23, 25, 80, 8080, 53, 67, 68, 443, 993, 143, 110]
list_of_ports.sort()
if (local == False):
print "local = false"
for port in list_of_ports:
print "scanning: "+WAN_IP+":"+str(port)
software_banner = return_banner(WAN_IP, port)
if (software_banner != None):
dictionary_of_open_services[WAN_IP+":"+str(port)] = software_banner