摘要: 代码如下: # -*- coding: utf-8 -*- import socket def find_service_name(): protocolname = 'tcp' for port in [80, 25]: print 'Port:%s =>service name:%s' % (p 阅读全文
posted @ 2016-01-28 17:26 jamesben 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 代码如下: # -*- coding: utf-8 -*- import socket from binascii import hexlify def convert_ip4_address(): '''如果要使用低层网络函数,有时普通的字符串形式 的IP地址并不是很有用,需要把他们转换成打包后的 阅读全文
posted @ 2016-01-28 17:20 jamesben 阅读(560) 评论(0) 推荐(0) 编辑
摘要: 代码如下: # -*- coding: utf-8 -*- import socket def get_remote_machine_info(): remote_host = 'www.python.org' try: print 'IP address:%s' % socket.gethostb 阅读全文
posted @ 2016-01-28 16:54 jamesben 阅读(335) 评论(0) 推荐(0) 编辑
摘要: 代码如下: # -*- coding: utf-8 -*- import socket def print_machine_info(): host_name = socket.gethostname() ip_address = socket.gethostbyname(host_name) pr 阅读全文
posted @ 2016-01-28 16:47 jamesben 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 1、服务端 server.py # -*- coding: utf-8 -*- import socket import argparse host = 'localhost' data_payload = 2048 backlog = 5 def echo_server(port): # 建立一个 阅读全文
posted @ 2016-01-28 16:16 jamesben 阅读(1759) 评论(0) 推荐(0) 编辑
摘要: 1、pip install ntplib 2、思路:先创建一个NTPClient实例,然后在这个实例上调用request()方法,把NTP服务器的地址传入方法,向NTP服务器发起一个NTP请求,响应使用ctime()函数打印出来。 3、代码如下: # -*- coding: utf-8 -*- im 阅读全文
posted @ 2016-01-28 11:19 jamesben 阅读(449) 评论(0) 推荐(0) 编辑