python网络编程
来源:互联网 发布:淘宝好评评语 编辑:程序博客网 时间:2024/06/15 23:58
python网络编程攻略学习笔记
打印设备和IPV4地址:
import socketdef 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.
- Python网络编程例子
- Python的网络编程
- python网络编程
- Python网络编程
- Python的网络编程
- python_网络编程
- Python PycURL 网络编程
- python中的网络编程
- Python网络编程基础
- python网络编程
- python 网络编程
- Python网络编程基础
- python网络编程解疑
- python 网络编程1
- python网络编程
- python 网络编程学习
- [Python] 网络编程(Socket)
- python 网络编程
- Path Patterns 和 Patterns with Placeholders
- UDP通讯程序设计
- Tomcat部署发布JSP应用程序的三种方法
- AngularJS $http Service
- 自定义TableView 继承, cell, model
- python网络编程
- 《机器学习系统设计》之应用scikit-learn做文本分类(上)
- AngularJS Resource:与 RESTful API 交互
- 第二课 MongoDB 数据模型
- CSS学习笔记---(七)
- 关于java.util.List.subList用法
- Java IO
- [Vijos]P1257 水王争霸
- sprintf函数应用