简体   繁体   中英

how to get protocol from ip and port with Python3?

i need get protocol(HTTP, FTP, SSMTP, IMAP, ETC) from ip address and port with Python3.

Example:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
protocol = s.connect( ("localhost", 80 )
print protocol #print HTTP

In general, it's not possible to detect the protocol type of a server listening on some port. The best you can get is request the name of the service that is normally associated with some port number:

>>> socket.getservbyport(80)
'www'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM