如何在Python中为我的网络工作找到面向公众的IP?

有帮助吗?

解决方案

这将获取您的远程IP地址

import urllib
ip = urllib.urlopen('http://automation.whatismyip.com/n09230945.asp').read()

如果您不想依赖其他人,那么只需上传类似PHP脚本的内容:

<?php echo 

这将获取您的远程IP地址

import urllib
ip = urllib.urlopen('http://automation.whatismyip.com/n09230945.asp').read()

如果您不想依赖其他人,那么只需上传类似PHP脚本的内容:

<%
Dim UserIPAddress
UserIPAddress = Request.ServerVariables("REMOTE_ADDR")
%>

并更改Python中的URL,或者如果您更喜欢ASP:

<*>

注意:我不知道ASP,但我认为这可能是有用的,所以我用Google搜索。

SERVER['REMOTE_ADDR']; ?>

并更改Python中的URL,或者如果您更喜欢ASP:

<*>

注意:我不知道ASP,但我认为这可能是有用的,所以我用Google搜索。

其他提示

whatismyip.org更好......它只是将ip作为明文丢弃而没有多余的垃圾。

import urllib
ip = urllib.urlopen('http://whatismyip.org').read()

但是,如果不依赖网络外部的东西,就不可能轻易做到。

https://api.ipify.org/?format=json 非常直接前进

只需运行 requests.get(&quot; https://api.ipify.org/?format = json&quot;)。json()['ip'] >

如果您不介意咒骂,请尝试:

http://wtfismyip.com/json

将其与常用的urllib内容结合起来,正如其他人所表明的那样。

还有:

http://www.networksecuritytoolkit.org/nst/tools/ip.php

import urllib2
text = urllib2.urlopen('http://www.whatismyip.org').read()
urlRE=re.findall('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',text)
urlRE        

['146.148.123.123']

尝试将您可以找到的任何'findmyipsite'放入列表中并迭代它们以进行比较。这个似乎运作良好。

import requests
r = requests.get(r'http://jsonip.com')
# r = requests.get(r'https://ifconfig.co/json')
ip= r.json()['ip']
print('Your IP is {}'.format(ip))

参考

这很简单

>>> import urllib
>>> urllib.urlopen('http://icanhazip.com/').read().strip('\n')
'xx.xx.xx.xx'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top