Skip to content

Instantly share code, notes, and snippets.

@tieubinhco
Created April 7, 2021 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tieubinhco/81dc7e6508aaabe9d04d51dfb66d8a02 to your computer and use it in GitHub Desktop.
Save tieubinhco/81dc7e6508aaabe9d04d51dfb66d8a02 to your computer and use it in GitHub Desktop.
Get IP address python
## importing socket module
import socket
## getting the hostname by socket.gethostname() method
hostname = socket.gethostname()
## getting the IP address using socket.gethostbyname() method
ip_address = socket.gethostbyname(hostname)
## printing the hostname and ip_address
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment