@@ -91,7 +91,7 @@ def get_ipaddr(cls, ifname):
9191 return socket .inet_ntoa (fcntl .ioctl (
9292 s .fileno (),
9393 0x8915 , # SIOCGIFADDR
94- struct .pack ('256s' , ifname [:15 ])
94+ struct .pack ('256s' , ifname . encode ( 'utf-8' ) [:15 ])
9595 )[20 :24 ])
9696
9797 @classmethod
@@ -153,7 +153,11 @@ def start_as_client(cls):
153153 time .sleep (1.0 )
154154 out = os .system ("wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1" )
155155 out += os .system ("dhclient -1 wlan0" )
156- print (out )
156+ print ("start_as_client: " + str (out ))
157+ ipaddr = cls .get_ipaddr ("wlan0" )
158+ if ipaddr is None or "169.254" in ipaddr :
159+ os .system ("sudo pkill wpa_supplicant" )
160+ raise Exception ()
157161 try :
158162 cls .register_ipaddr (cls .get_macaddr ("wlan0" ), cls .get_config ().get ('bot_name' , 'CoderBot' ), cls .get_ipaddr ("wlan0" ), "roberto.previtera@gmail.com" )
159163 print ("registered bot, ip: " + str (cls .get_ipaddr ("wlan0" ) + " name: " + cls .get_config ().get ('bot_name' , 'CoderBot' )))
@@ -175,7 +179,7 @@ def start_as_ap(cls):
175179 out += str (subprocess .check_output (["ip" , "a" , "add" , "10.0.0.1/24" , "dev" , "wlan0" ]))
176180 out += str (subprocess .check_output (["ip" , "link" , "set" , "dev" , "wlan0" , "up" ]))
177181 out += str (subprocess .check_output (["ifconfig" ]))
178- print (out )
182+ print ("start_as_ap: " + str ( out ) )
179183 cls .start_hostapd ()
180184 cls .start_dnsmasq ()
181185
0 commit comments