Skip to content

Instantly share code, notes, and snippets.

@yankchina
Created April 5, 2015 08:26
Show Gist options
  • Save yankchina/8cd317eaa357ca6524a6 to your computer and use it in GitHub Desktop.
Save yankchina/8cd317eaa357ca6524a6 to your computer and use it in GitHub Desktop.
判定 Android 是否连上 WiFi,并且获取当前 IP 地址
import sl4a
import socket, struct
def check_wifi_info():
droid = sl4a.Android()
wifiState = droid.checkWifiState()
if wifiState:
ipdec = droid.wifiGetConnectionInfo().result['ip_address']
ipstr = socket.inet_ntoa(struct.pack('L',ipdec))
droid.makeToast(ipstr)
return wifiState
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment