python 获取当前ip】的更多相关文章

python获取公网ip的几种方式       from urllib2 import urlopen   my_ip = urlopen('http://ip.42.pl/raw').read()   print 'ip.42.pl', my_ip       from json import load   from urllib2 import urlopen       my_ip = load(urlopen('http://jsonip.com'))['ip']   print 'js…
python获取公网ip的几种方式 转 https://blog.csdn.net/conquerwave/article/details/77666226 from urllib2 import urlopen   my_ip = urlopen('http://ip.42.pl/raw').read()   print 'ip.42.pl', my_ip       from json import load   from urllib2 import urlopen       my_ip…
原文 见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 #!/usr/bin/env python # -*- coding: utf-8 -*- import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcnt…
获取主机内网,外网IP,主机名 代码如下: #!/usr/bin/env python #-*- coding:utf-8 -*- # author:Zeng Xianhe import socket import fcntl,struct import time def getHardware(outip,inip): sk = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) ##1.获取主机名 hostname = socket.gethos…
利用requests库获取代理,用Beautiful库解析网页筛选ip # -*- coding: utf- -*- import requests from bs4 import BeautifulSoup from threading import Thread headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0'} #定义获取IP函数…
python2.7 #!/usr/bin/env python # Python Network Programming Cookbook -- Chapter - # This program is optimized for Python 2.7. # It may run on any other version with/without modifications. import socket def get_remote_machine_info(): remote_host = 'w…
import socket # 获取本机计算机名称 hostname = socket.gethostname() # 获取本机ip ip = socket.gethostbyname(hostname) print(ip)…
#_*_coding:utf8_*_ #以下两种方法可以在ubuntu下或者windows下获得本地的IP地址 import socket # 方法一 localIP = socket.gethostbyname(socket.gethostname()) print ("local ip address: %s"%localIP) ipList = socket.gethostbyname_ex(socket.gethostname()) # 循环打印 for i in ipList…
# coding: utf-8 import urllib2 import re import time def getDL(page): url = 'http://www.xicidaili.com/nt/{}'.format(page) header = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 S…
from urllib2 import urlopen my_ip = urlopen('http://ip.42.pl/raw').read() print 'ip.42.pl', my_ip from json import load from urllib2 import urlopen my_ip = load(urlopen('http://jsonip.com'))['ip'] print 'jsonip.com', my_ip from json import load from…