@@ -91,7 +91,7 @@ def get_ipaddr(cls, ifname):
91
91
return socket .inet_ntoa (fcntl .ioctl (
92
92
s .fileno (),
93
93
0x8915 , # SIOCGIFADDR
94
- struct .pack ('256s' , ifname [:15 ])
94
+ struct .pack ('256s' , ifname . encode ( 'utf-8' ) [:15 ])
95
95
)[20 :24 ])
96
96
97
97
@classmethod
@@ -153,7 +153,11 @@ def start_as_client(cls):
153
153
time .sleep (1.0 )
154
154
out = os .system ("wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1" )
155
155
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 ()
157
161
try :
158
162
cls .
register_ipaddr (
cls .
get_macaddr (
"wlan0" ),
cls .
get_config ().
get (
'bot_name' ,
'CoderBot' ),
cls .
get_ipaddr (
"wlan0" ),
"[email protected] " )
159
163
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):
175
179
out += str (subprocess .check_output (["ip" , "a" , "add" , "10.0.0.1/24" , "dev" , "wlan0" ]))
176
180
out += str (subprocess .check_output (["ip" , "link" , "set" , "dev" , "wlan0" , "up" ]))
177
181
out += str (subprocess .check_output (["ifconfig" ]))
178
- print (out )
182
+ print ("start_as_ap: " + str ( out ) )
179
183
cls .start_hostapd ()
180
184
cls .start_dnsmasq ()
181
185
0 commit comments