由于最近在学习网络编程,喜欢玩IP地址。

首先,我需要搞清楚如何获得本机IP。

===========================================11.04=================================================
我去,更奇怪的事情出现了。
1、
我用http://test-ipv6.com/做IPv6测试,测试结果为0/10.
但这不重要,重要的是今天(11.04)它告诉我本机IP是:111.17.191.79
2、
当我百度关键字“公网IP”时,百度告诉为我的IP地址为:219.146.245.35
3、
当我使用python获取IP地址时:
Python 3.3.3 (default, Sep  6 2014, 10:53:40) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> print(socket.gethostbyname(socket.gethostname()))
219.146.13.36
IP地址:219.146.13.36
4、当我调用bash命令:ifconfig时:
ppp0      Link encap:Point-to-Point Protocol
inet addr:180.201.198.204 P-t-P:192.168.100.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (9.8 MiB) TX bytes: (1.4 MiB)

IP地址:180.120.198.204

四种方法得到四个IP地址。很有意思啊。
=================================================尝试分析==========================================================
1、第一种方法和第二种方法得到的IP地址来源原理未知,暂不做讨论。
2、利用python获得IP地址,用到了两个函数socket.gethostname()、socket.gethostbyname()
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()
Translate a host name to IPv4 address format. The IPv4 address is returned as a string, such as '100.50.200.5'. If the host name is 
an IPv4 address itself it is returned unchanged. See gethostbyname_ex() for a more complete interface. gethostbyname() does not
support IPv6 name resolution, and getaddrinfo() should be used instead for IPv4/v6 dual stack support.
												

最新文章

  1. Cesium应用篇:3控件(2)BaseLayerPicker
  2. history.back新页面跳转
  3. 给锁住的行解锁(oracle)
  4. UTF-8和Unicode
  5. 操作系统:cpu调度 6-25
  6. linux 下安装rsync
  7. .NET设计模式(11):组合模式(Composite Pattern)(转)
  8. SqlServer Change Data Capture(CDC)数据变更捕获
  9. AST抽象语法树
  10. STL之deque(双向队列)
  11. Liveness 探测 - 每天5分钟玩转 Docker 容器技术(143)
  12. 免费 web 后台管理 网站
  13. 2017-09-16 ADB Shell+Putty
  14. 交叉编译bash
  15. Eclipse 下载安装
  16. R 语言 Windows 环境 安装与Windows下制作R的package--Rtools
  17. rviz1
  18. python爬虫(二)
  19. 第三方git pull免密码更新
  20. mysql8.0 在window环境下的部署与配置

热门文章

  1. Servlet中使用 Last-Modified、Expires和Cache-Control
  2. Web.Config文件配置之限制上传文件大小和时间
  3. python+selenium 组织用例方式 总结
  4. Nginx 的安装配置入门(mac)
  5. paramiko 使用总结(SSH 操作远端机器)
  6. log4j笔记:升级2.X版本的日志滚动问题
  7. golang笔记:net/smtp
  8. [BZOJ2823][BZOJ1336][BZOJ1337]最小圆覆盖(随机增量法)
  9. [CF911D]Inversion Counting
  10. 一年的天数 Exercise06_16