python实现根据主机名字获得所有ip地址的方法

yipeiwu_com6年前Python基础

本文实例讲述了python实现根据主机名字获得所有ip地址的方法。分享给大家供大家参考。具体实现方法如下:

# -*- coding: utf-8 -*-
import sys, socket
result = socket.getaddrinfo('www.google.com', None, 0, socket.SOCK_STREAM)
counter = 0
for item in result:
  print "%-2d: %s" % (counter, item[4])
  counter += 1

运行结果:

0 : ('74.125.128.106', 0)
1 : ('74.125.128.147', 0)
2 : ('74.125.128.99', 0)
3 : ('74.125.128.103', 0)
4 : ('74.125.128.104', 0)
5 : ('74.125.128.105', 0)

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python 如何将数据写入本地txt文本文件的实现方法

一、读写txt文件 1、打开txt文件 file_handle=open('1.txt',mode='w') 上述函数参数有(1.文件名,mode模式) mode模式有以下几种...

利用OpenCV和Python实现查找图片差异

利用OpenCV和Python实现查找图片差异

使用OpenCV和Python查找图片差异 flyfish 方法1 均方误差的算法(Mean Squared Error , MSE) 下面的一些表达与《TensorFlow - 协方...

django celery redis使用具体实践

django celery redis使用具体实践

环境准备 python3.5.4 windows redis pip install celery pip install redis windows下启动redir...

python制作图片缩略图

python制作图片缩略图

缩略图 在很多时候我们都需要将图片按照同比例缩小有利于存储 但是一张张手动去改的话太麻烦了 今天我们就用python实现一个简单的将一个文件夹中的所有图片进行指定大小的调整 缩略前:...

python实现给微信指定好友定时发送消息

python实现给微信指定好友定时发送消息

python有很多有趣的库,其中wxpy是连接微信的接口,具体可以查看官方文档。可以实现自动操作,wxpy 支持 Python 3.4-3.6,以及 2.7 版本。 一、安装 win10...