我有一段python代码可以监听端口。我想要的最终结果是,当任何人对该IP运行nmap时,自定义名称会显示在服务名称列中。为了说明我的要求,请参阅下面的屏幕截图,其中显示端口666为名称厄运。
我试图寻找解决方案但没有任何成功。
下面是我用来监听端口的python代码:
import socket
import sys
HOST = '' # Symbolic name, meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
#Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
#Start listening on socket
s.listen(10)
print 'Socket now listening'
#now keep talking with the client
while 1:
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
s.close()
如果有人能指出我正确的方向或帮助我修改这些代码,我会非常感激。