Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?

1 Answer

0 votes
by (106k points)

To find local IP addresses using Python's stdlib you can say use socket module and you will have your IP address:-

You need to run the following piece of code:-

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80))

print(s.getsockname()[0]) s.close()

image

But before running makes sure you have internet access, and also there is no local proxy.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...