我是python和socket编程的新手,尝试扫描广域网地址的端口。在
通过使用nmap,我知道他打开了端口80和443。在
为什么我不能从它上面看一下它是不是开着的???另外,当我用程序扫描网关时,它显示21和23是打开的,这也是NMAP显示的。但是nmap也告诉我有端口80和443,但是我的程序没有接收到它们。在
谢谢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