0 votes
1 view
in Python by (47.8k 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 (107k 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.

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


Categories

...