Get the Current Public IP Address

I saw someone sharing an open source Py library to get the current IP on v2ex, Which remind me that the proxy crawler I wrote before was verified by Taobao’s API. There are concurrency restrictions, and maybe I can change it to a better way.

Comparison Of Various Ways

Let me talk about a particularly amazing way

1
nc ns1.dnspod.net 6666

The data returned is IP, and the speed is very fast.

There are also various ways based on curl, such as

1
2
3
4
5
6
curl ip.cn
curl ifconfig.me
curl haoip.cn
curl myip.ipip.net
curl ipinfo.io
curl httpbin.org/ip

If you have a large demand for access, buy a VPS, and build a Web Server to return the IP in the HTTP Header. Here is what I try with Python.

First, install the flask, local debugging is best to install virtualenv

1
2
3
4
5
6
7
8
9
10
from flask import Flask, request

app = Flask(__name__)

@app.route('/')
def hello_world():
return request.remote_addr

if __name__ == '__main__':
app.run()

I did not use the pressure measurement tool to measure, But I think is not bad. If you have running Nginx, you should consider the IP change of the forwarding process, mainly the HTTP_X_FORWARDED_FOR part.

Additional

The performance should improve a lot if we use Go but not Python.

After obtaining the public network IP and matching the domain name resolution interface, and using DMZ, it is actually another type of Ory DDNS.