How can I find my IP In Python ?

+1 Roy Berenshteyn · November 21, 2015
How can I find my Ip In Python ?

                                                                 Thanks <Roy>   

Post a Reply

Replies

Oldest  Newest  Rating
0 Dol Lod · November 22, 2015
http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib

Maybe. Looks rightish.
0 Myron Ortiz · November 22, 2015
Here are the ways to get your IP address. 

For your local IP address
import socket

socket.gethostbyname(socket.gethostname())


While this is how to get your network IP adddress


your_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
your_socket.connect(("gmail.com",80))
print(your_socket.getsockname()[0])
your_socket.close()
  • 1

Python

107,003 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator