Files
AnaLogger/test/grabIP.py
T
Marco Locatelli ce2e4c523e initial commit
2021-03-09 15:22:10 +01:00

16 lines
400 B
Python

# To get the IPv4 IP address of the local machine using
# Using socket module and socket.socket() and connect()
# and socket.getsockname() Method in Python
# Import Module
import socket
# Create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# connect to the server on local computer
s.connect(("8.8.8.8", 80))
# Print Output
print("HostName: ",s.getsockname()[0])
s.close()