0

I am trying to get the SSID of the WiFi network I am connected to in Python using the socket module. It's probably dead simple but I can't seem to figure it out.

Here is my code so far:

import socket
hostname = socket.gethostname()
IPAddress = socket.gethostbyname(hostname)
print("SSIP: " + hostname)
print("IP-Adress: " + IPAddress)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
me4gqp
  • 11
  • 1
  • 9
  • But the hostname is not the name of the SSIP. It seems that socket doesn't offer a specific get-function for that. – me4gqp Apr 20 '20 at 13:54
  • Naoh Broyles, yes I want to get the name of the wifi network I'm connected too. – me4gqp Apr 20 '20 at 15:43
  • Does this answer your question? [How do I get Python to know what Wifi the user is connected to?](https://stackoverflow.com/questions/33227160/how-do-i-get-python-to-know-what-wifi-the-user-is-connected-to) – mkrieger1 Apr 20 '20 at 16:03
  • If not, then https://stackoverflow.com/questions/35706483/how-would-i-find-the-ssid-of-a-network-in-python-3 – mkrieger1 Apr 20 '20 at 16:03
  • mkrieger1, I'm aware of the solution using the subprocess-module, but I want to use the socket-module. – me4gqp Apr 20 '20 at 16:08
  • I don't think the socket knows anything about SSIDs. – mkrieger1 Apr 20 '20 at 16:10
  • A socket is a generic interface to *any kind of network whatsoever*, the majority of which have no concept of anything resembling a SSID. The `socket` module is not the right place to look for a solution here. – jasonharper Apr 20 '20 at 16:11
  • So there is no possibility using socket ? – me4gqp Apr 20 '20 at 16:13

1 Answers1

1

Here is what you can do :

import os
ssid=os.popen("sudo iwgetid -r").read()
Marin
  • 11
  • 1