looking ip with python code example

Example 1: get IP address python

import socket    
hostname = socket.gethostname()    
IPAddr = socket.gethostbyname(hostname)    
print("Your Computer Name is:" + hostname)    
print("Your Computer IP Address is:" + IPAddr) 
#How to get the IP address of a client using socket

Example 2: how to get local ip in python

import socket
local_ip = socket.gethostbyname(socket.gethostname)
print(f"[+] Your Local IP is : {local_ip}")

Example 3: how to get local ip in python

import socket
local_ip = socket.gethostbyname(socket.gethostname())
print(f"[+] Your Local IP is : {local_ip}")