How to find local IP addresses using Python s stdlib

0 votes
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?
Dec 8, 2020 in Python by kartik
• 37,520 points
984 views

1 answer to this question.

0 votes

Hello @kartik,

Try this out:

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

This assumes you have an internet access, and that there is no local proxy.

answered Dec 8, 2020 by Niroj
• 82,840 points

Related Questions In Python

0 votes
2 answers

Finding local IP addresses using Python's stdlib

import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s ...READ MORE

answered Mar 30, 2020 in Python by anonymous
3,064 views
0 votes
1 answer

How to find packages installed using pip?

Yes, you can find the packages installed ...READ MORE

answered Jan 29, 2019 in Python by Omkar
• 69,220 points
718 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,422 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,041 views
0 votes
1 answer

How to perform HTML decoding/encoding using Python/Django?

Hello, For html encoding, there's cgi.escape from the standard library: >> ...READ MORE

answered May 7, 2020 in Python by Niroj
• 82,840 points
13,368 views
0 votes
1 answer

How to Install Python packages from local file system folder to virtualenv with pip?

Hello @kartik, You can try the code below: pip ...READ MORE

answered May 12, 2020 in Python by Niroj
• 82,840 points

edited Oct 7, 2021 by Sarfaraz 13,319 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP