0

I get a 127.0.1.1 address when I use the socket library.

I'd like to get my router assigned IP address which is 192.168.0.10. I can find this IP running ifconfig on my wifi adapter which is inconsistently named between my PC and my laptop so using subprocess is not the most efficient way to do this.

SomeGuyOnAComputer
  • 5,414
  • 6
  • 40
  • 72

1 Answers1

0
import netifaces
def find_gateway():
      Interfaces= netifaces.interfaces()
      for inter in Interfaces:
           if inter == "wlan0":
                temp_list = []
                Addresses = netifaces.ifaddresses(inter)
                gws = netifaces.gateways()
                temp_list = list (gws['default'][netifaces.AF_INET])
                count =0 
                for item in temp_list:
                      count +=1
                      if count ==1:
                           print (item)
                      else:
                           pass
find_gateway()

I hope this gives you what you want modules used netifaces (pip install netifaces)

KGBGUY
  • 29
  • 5