Get IP Address in Python

0

Get IP Address in Python

  • To get IP address of your computer in python, you have to first import socket library and then use socket.gethostbyname(socket.gethostname()) code inside the print() statement to print your IP address as output as shown in the program given below.

Python Programming Code to Get IP Address

import socket
print("Want to get IP Address ? (y/n): ")
check = input()
if check == 'n':
    exit()
else:
    print("\nYour IP Address is: ",end="")
    print(socket.gethostbyname(socket.gethostname()))
 
 
 

 

 

Post a Comment

0Comments
Post a Comment (0)