I have a VPN Docker container set up using Gluetun, which is running an HTTP Proxy, I’m trying to see if it’s possible to do a Lua http.request to retrieve both my direct (local) external IP, AND my tunnelled external IP too?
I’ve found a few pages that help explain how I might do this, but I’m not sure how to retrieve both continuously. (Main page being)
Fetching page of url using luasocket and proxy
Here is my current code.
local url = require "socket.url"
local http = require "socket.http"
print("----------EXTERNAL IP DIRECT---------------")
local result, status = http.request("http://api.ipify.org/")
print(result, status)
print("---------EXTERNAL IP VIA PROXY-------------")
http.PROXY="http://192.168.102.134:8888/" -- locally hosted http proxy, no name/password
local result1, status1 = http.request("http://api.ipify.org/")
print(result1, status1)
When I run this first, I get the following.
---------EXTERNAL IP DIRECT---------------
2.234.10.99 200
---------EXTERNAL IP VIA PROXY-------------
192.168.102.107 200
Which provides my external IP fine, but the bottom proxy IP listed is the local IP of the machine I’m running the code on, which surprised me, also every subsequent running of the code returns my local IP for both.
----------EXTERNAL IP DIRECT---------------
192.168.102.107 200
---------EXTERNAL IP VIA PROXY-------------
192.168.102.107 200
Observations.. When I set the http.proxy value, that seems to be retained for all subsequent requests. I can see the requests recorded positively on the (Gluetun) http proxy container logs, so they are being passed ok.
Does anyone have any ideas on how Lua can act as a http client to retrieve my tunnels external IP?