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,490 points
75 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,580 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
1,040 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,090 points
120 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,858 views
0 votes
0 answers
+4 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,810 points
1,432 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 6, 2020 in Python by Niroj
• 82,580 points
8,440 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 11, 2020 in Python by Niroj
• 82,580 points
4,618 views