HomeSoftware EngineeringHow you can get the IP Tackle in Python

How you can get the IP Tackle in Python


If you should get the IP Tackle in your Python software, then you are able to do the next:

Choice 1 – Utilizing socket.gethostname()

import socket
print(socket.gethostbyname(socket.gethostname()))

Choice 2 – Utilizing socket.getsockname()

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.join(("8.8.8.8", 80))
print(s.getsockname()[0])

Choice 3 – Utilizing the netifaces module

from netifaces import interfaces, ifaddresses, AF_INET
for ifaceName in interfaces():
    addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}] )]
    print(' '.be a part of(addresses))
RELATED ARTICLES

Most Popular

Recent Comments