python2.5_1.5_通过指定的端口和协议找到服务名

代码如下:

# -*- coding: utf-8 -*-
import socket def find_service_name():
protocolname = 'tcp'
for port in [80, 25]:
print 'Port:%s =>service name:%s' % (port, socket.getservbyport(port, protocolname))
print 'Port:%s =>service name:%s' % (53, socket.getservbyport(53, 'udp')) if __name__ == '__main__':
find_service_name()

运行结果如下:

Port: =>service name:http
Port: =>service name:domain
Port: =>service name:smtp
Port: =>service name:domain
上一篇:获取百度地图POI数据一(详解百度返回的POI数据)


下一篇:微信小程序,天气预报(百度地图开放平台API)