Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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(("", 80))

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


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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.2k users

Browse Categories