Python sockets IP bekommen?
Ich möchte in Python die IP-Adresse von dem Gerät finden, auf dem das Skript ausgeführt wird. Das Internet sagt ich soll socket benutzen, aber bei pip install socket kommt: "ERROR: Could not find a version that satisfies the requirement socket (from versions: none)". pip install sockets funktioniert, dann funktioniert jedoch sockets.gethostname() nicht.
Mein Code:
import sockets
from sockets import *
hostname = sockets.gethostname()
IPaddress = sockets.gethostbyname(hostname)
print(f"Hostname: {hostname}\nIP Address: {IPaddress}")
Ergänzung:
Code gibt den Fehler "AttributeError: module 'sockets' has no attribute 'gethostname'"
1 Antwort
Vom Beitragsersteller als hilfreich ausgezeichnet
Von gutefrage auf Grund seines Wissens auf einem Fachgebiet ausgezeichneter Nutzer
programmieren, Programmiersprache, Python
Das socket-Modul ist Teil der Standardbibliothek von Python.
https://docs.python.org/3/library/socket.html#socket.gethostname
Du hast dir via pip eine gleichnamige Bibliothek gezogen.