Unk*_*ech 14
这将获取您的远程IP地址
import urllib
ip = urllib.urlopen('http://automation.whatismyip.com/n09230945.asp').read()
Run Code Online (Sandbox Code Playgroud)
如果您不想依赖其他人,那么只需上传类似这个PHP脚本的内容:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
Run Code Online (Sandbox Code Playgroud)
并更改Python中的URL或者您更喜欢ASP:
<%
Dim UserIPAddress
UserIPAddress = Request.ServerVariables("REMOTE_ADDR")
%>
Run Code Online (Sandbox Code Playgroud)
注意:我不知道ASP,但我认为这可能是有用的,所以我google了.
whatismyip.org更好......它只是将ip作为明文丢弃而没有多余的垃圾.
import urllib
ip = urllib.urlopen('http://whatismyip.org').read()
Run Code Online (Sandbox Code Playgroud)
但是,如果不依赖网络本身以外的东西,就不可能轻易做到.
https://api.ipify.org/?format=json非常简单
可以通过运行来解析 requests.get("https://api.ipify.org/?format=json").json()['ip']
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))
Run Code Online (Sandbox Code Playgroud)