Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loopback IP instead of local IP used on Linux #21

Closed
scutumelectrum opened this issue Nov 21, 2022 · 2 comments
Closed

Loopback IP instead of local IP used on Linux #21

scutumelectrum opened this issue Nov 21, 2022 · 2 comments
Assignees

Comments

@scutumelectrum
Copy link

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).

@cybermaggedon cybermaggedon self-assigned this Dec 3, 2022
@awltux
Copy link
Contributor

awltux commented Jan 31, 2023

I think I fixed this in my pull request

@cybermaggedon
Copy link
Owner

Closed in the PR ref'd above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants