Answers for "get ip with python"

10

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
Posted by: Guest on April-02-2020
1

get ip python

import socket    
host = socket.getfqdn()    
addr = socket.gethostbyname(host)
print(f"Your ip is {addr}")
# On Linux, it may give you the localhost address
Posted by: Guest on November-18-2020
0

how to get local ip in python

import socket
local_ip = socket.gethostbyname(socket.gethostname())
print(f"[+] Your Local IP is : {local_ip}")
Posted by: Guest on May-28-2021
1

python get lan ip

import socket
def get_ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # doesn't even have to be reachable
        s.connect(('10.255.255.255', 1))
        IP = s.getsockname()[0]
    except Exception:
        IP = '127.0.0.1'
    finally:
        s.close()
    return IP
Posted by: Guest on June-19-2020

Python Answers by Framework

Browse Popular Code Answers by Language