python网络编程
2015-08-12 22:09
477 查看
python网络编程基础
python网络编程攻略学习笔记
打印设备和IPV4地址:
socket.gethostname() 没有参数 获得所在主机或本地主机的名字
socket.gethostbyname(hostname) 接受一个hostname 返回对应的ip
地址
python手册查询信息:
socket.gethostname():
Return a string containing the hostname of the machine where the Python interpreter is currently executing.
If you want to know the current machine’s IP address, you may want to use gethostbyname(gethostname()). This operation assumes that there is a valid address-to-host mapping for the host, and the assumption does not always hold.
Note: gethostname() doesn’t always return the fully qualified domain name; use getfqdn() (see above).
socket.gethostbyname(hostname):
Translate a host name to IPv4 address format, extended interface. Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host name responding to the given ip_address, aliaslist is a (possibly empty) list of alternative host names for the same address, and ipaddrlist is a list of IPv4 addresses for the same interface on the same host (often but not always a single address). gethostbyname_ex() does not support IPv6 name resolution, and getaddrinfo() should be used instead for IPv4/v6 dual stack support.
python网络编程攻略学习笔记
打印设备和IPV4地址:
import socket def print_machine_info(): host_name = socket.gethostname() ip_address = socket.gethostbyname(host_name) print ("host name: %s" % host_name) print ("ip address: %s" % ip_address)
socket.gethostname() 没有参数 获得所在主机或本地主机的名字
>>>help(socket.gethostname) Help on built-in function gethostname in module _socket: gethostname(...) gethostname() -> string Return the current host name.
socket.gethostbyname(hostname) 接受一个hostname 返回对应的ip
地址
>>>help(socket.gethostbyname) Help on built-in function gethostbyname in module _socket: gethostbyname(...) gethostbyname(host) -> address Return the IP address (a string of the form '255.255.255.255') for a host.
python手册查询信息:
socket.gethostname():
Return a string containing the hostname of the machine where the Python interpreter is currently executing.
If you want to know the current machine’s IP address, you may want to use gethostbyname(gethostname()). This operation assumes that there is a valid address-to-host mapping for the host, and the assumption does not always hold.
Note: gethostname() doesn’t always return the fully qualified domain name; use getfqdn() (see above).
socket.gethostbyname(hostname):
Translate a host name to IPv4 address format, extended interface. Return a triple (hostname, aliaslist, ipaddrlist) where hostname is the primary host name responding to the given ip_address, aliaslist is a (possibly empty) list of alternative host names for the same address, and ipaddrlist is a list of IPv4 addresses for the same interface on the same host (often but not always a single address). gethostbyname_ex() does not support IPv6 name resolution, and getaddrinfo() should be used instead for IPv4/v6 dual stack support.
相关文章推荐
- AngularJS $http Service
- TCP通讯程序设计
- twisted.http 异步访问站点
- 工具类:MD5加密
- 工具类:处理网络请求的回应
- HttpClient发送网络请求
- CentOS 6.6上使用httpd做YUM仓库
- Android--HttpURLConnection
- 深入理解TCP(一)
- Volley网络框架完全解析(使用篇)
- Android开发案例:网络交互&XML与json数据解析&HttpUtil优化
- HttpUrlConnection
- c#网络编程资料
- 【工业串口和网络软件通讯平台(SuperIO)教程】五.二次开发图形显示界面
- 【工业串口和网络软件通讯平台(SuperIO)教程】五.二次开发图形显示界面
- HttpClient网络连接
- 08-12 Serverlet 数据库连接、doPost方法 HttpClientDoGet HTTPClientDoPost
- HTTP协议
- Android网络状况查询
- .Net C# Winform 中判断本地系统的网络连接状态的方法