SHARE
TWEET

186-Get local IP address

steve-shambles-2109 Oct 23rd, 2019 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2. Python code snippets vol 38:
  3. 186-Get local IP address
  4. stevepython.wordpress.com
  5.  
  6. requirements:None
  7.  
  8. source:
  9. https://gist.github.com/MattWoodhead/541f23ecd9b464adf2b2e1598aa9261d
  10. '''
  11. import socket
  12.  
  13. def ip_check():
  14.     """ uses the sockets module to find the local IP address """
  15.     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  16.     s.connect(("8.8.8.8", 80))  # Ping Google DNS server
  17.     ip_address = s.getsockname()[0]
  18.     s.close()
  19.     return ip_address
  20.  
  21. print(ip_check())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top