项目作者: bruno-garcia

项目描述 :
API to lookup HTTP proxy information
高级语言: C#
项目地址: git://github.com/bruno-garcia/HttpProxyControl.git
创建时间: 2017-12-16T17:23:10Z
项目社区:https://github.com/bruno-garcia/HttpProxyControl

开源协议:

下载


HTTP Proxy Control

With a simple solution using Docker and OpenVPN+Privoxy
it’s possible to have HTTP proxies (and network gateways) in your local network which allow you browse using IP addresses of different countries.

This is especially useful to watch Netflix from different countries amongs other things. While the proxy is handy to configure directly on a web browser, the network gateway can be directly configured to a smart TV so all traffic from the TV goes through the tunnel (and the country) of the backing VPN.

The motivation to this little API was to provide data to web page which contains status information about these tunnels. One situation that has happend before was the VPN connection dropping and not reconnecting. The HTTP proxy and network gateway continued to work but the connections through those ended up using the local network’s gateway instead. Another point is sudden latency spikes and buffer times on streaming services.

Getting information about a proxy

GET /proxy/info/host:port

This endpoint returns:

  • Public IP address of the current network
  • Public IP address of the proxy (i.e: VPN tunnel)
  • Country of the current network’s IP address
  • Country of the proxy server’s IP address
  • Latency to the proxy server tested with ICMP echo

The overall response time will be around the same as the longest dependency took to respond. Keeping in mind that to resolve the country the API first needs to get the external IP address. It does so in two calls to external services.

Running

.NET Core 2 SDK is required to build and run:

To run it in development mode

  1. git clone https://github.com/bruno-garcia/HttpProxyControl.git
  2. cd HttpProxyControl
  3. dotnet run

An example of setting it up on Linux with iptables:

  1. git clone https://github.com/bruno-garcia/HttpProxyControl.git
  2. cd HttpProxyControl
  3. # choose a port
  4. port=31337
  5. iptables -A INPUT -i eth0 -p tcp --dport $port -j ACCEPT
  6. export ASPNETCORE_URLS=http://*:$port
  7. dotnet publish HttpProxyControl.sln -c Release -o out
  8. dotnet out/HttpProxyInfo.dll

Example call:

  1. curl -X GET --header 'Accept: application/json' 'http://server/proxy/info/proxy.lan%3A8118'
  1. {
  2. "latencyToProxy": {
  3. "latency": "00:00:01.0052416",
  4. "errorMessage": "TimedOut"
  5. },
  6. "proxyPublicIp": {
  7. "ip": "128.90.1.1",
  8. "latency": "00:00:00.8936781"
  9. },
  10. "proxyCountry": {
  11. "country": "CH",
  12. "latency": "00:00:00.4429030"
  13. },
  14. "serverPublicIp": {
  15. "ip": "84.114.1.1",
  16. "latency": "00:00:00.5943200"
  17. },
  18. "serverCountry": {
  19. "country": "AT",
  20. "latency": "00:00:00.5102278"
  21. }
  22. }

The proxy server is filtering ICMP so latency check times out after 1 second.

  1. {
  2. "latencyToProxy": {
  3. "latency": "00:00:00.0020000"
  4. },
  5. "proxyPublicIp": {
  6. "ip": "69.167.1.1",
  7. "latency": "00:00:00.1275722"
  8. },
  9. "proxyCountry": {
  10. "country": "US",
  11. "latency": "00:00:00.1689354"
  12. },
  13. "serverPublicIp": {
  14. "ip": "84.114.1.1",
  15. "latency": "00:00:00.1393001"
  16. },
  17. "serverCountry": {
  18. "country": "AT",
  19. "latency": "00:00:00.1799295"
  20. }

Another call with a successful response to the ICMP echo request.

Swagger

The code generates OpenAPI information (aka: swagger) and includes swagger UI:

Swagger

External APIs

To verify the public IP address, the code calls: https://api.ipify.org.

To verify the country of that IP address: https://ipinfo.io/{ipAddress}/country.