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

MacOS: Unable to get private IP address #6

Open
amirsoroush opened this issue Mar 24, 2024 · 0 comments
Open

MacOS: Unable to get private IP address #6

amirsoroush opened this issue Mar 24, 2024 · 0 comments

Comments

@amirsoroush
Copy link

ip command is not installed by default in MacOS(Sonoma).

Probably something like below can do the job(in my machine at least):

ifconfig en0 | grep -E 'inet\b' | cut -f 2 -d ' '

Linux also has ifconfig installed but it's deprecated now.

There is another cross-platform solution like:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
print(s.getsockname()[0])
s.close()

But it needs internet connection.

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

1 participant