cybermaggedon / gnucash-uk-vat

A bridge between GnuCash and UK HMRC VAT return MTD APIs for automating VAT returns
GNU General Public License v3.0
13 stars 2 forks source link

Loopback IP instead of local IP used on Linux #21

Closed scutumelectrum closed 3 months ago

scutumelectrum commented 2 years ago

Found an unexpected bug, the "Gov-Client-Local-IPs" header is populated with the loopback address ("127.x") on Linux, and not the local IP address. This is because Python's socket.getbyhostname() returns the value in /etc/hosts, which usually has the loopback address.

On Win and Mac OS the behaviour seems to be correct, but I haven't tested for myself.

After a bit of searching, I found a solution like this (which doesn't add extra dep's):

def get_ip_address():
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
    s.connect(("192.168.1.1", 80)) 
    return s.getsockname()[0]

Unfortunately I don't know how to get the gateway IP, so the code above uses my default (the example used 8.8.8.8, but I don't want to open connections externally if it's not needed).

awltux commented 1 year ago

I think I fixed this in my pull request

cybermaggedon commented 3 months ago

Closed in the PR ref'd above