Prześlij pliki do "app"
This commit is contained in:
1 parent
26bff5bbcf
commit
122989c6bb
1 file changed
+27
@@ -0,0 +1,27 @@
|
|||||||
|
# app/network_manager.py
|
||||||
|
import socket
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class NetworkManager:
|
||||||
|
"""Prosta pomocnicza klasa, dostarcza aktualny adres IP."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_ip_addresses():
|
||||||
|
"""Zwraca listę adresów IPv4 przypisanych do interfejsów."""
|
||||||
|
ips = []
|
||||||
|
hostname = socket.gethostname()
|
||||||
|
try:
|
||||||
|
host_ip = socket.gethostbyname(hostname)
|
||||||
|
ips.append(host_ip)
|
||||||
|
except socket.error:
|
||||||
|
pass
|
||||||
|
# Dodajemy dodatkowo wszystkie interfejsy, jeśli system obsługuje getaddrinfo
|
||||||
|
for info in socket.getaddrinfo(hostname, None, socket.AF_INET):
|
||||||
|
ip = info[4][0]
|
||||||
|
if ip not in ips:
|
||||||
|
ips.append(ip)
|
||||||
|
log.debug("IP addresses: %s", ips)
|
||||||
|
return ips
|
||||||
Reference in new issue
Block a user