簡體   English   中英

使用Python腳本檢查android設備是否已連接到互聯網

[英]Python script to check if android device is connected to internet

我正在編寫一個python腳本來檢查我的android設備是否已連接到互聯網。 我正在嘗試在adb shell中執行以下操作:

  1. busybox遠程登錄173.194.33.97 80
  2. GET / HTTP / 1.0

輸出為:-HTTP / 1.0 200 OK

我只關心HTTP / 1.0 200 OK,以檢查Internet連接。

我試圖在python中使用netcat,但是我沒有很好的經驗來實現它。

任何幫助將不勝感激!

最后,Python腳本是:

cmd = "adb shell \"echo \'GET / HTTP/1.0\n\n\' | nc 173.194.33.103 80\""
p = Popen(shlex.split(cmd), stdout=PIPE, stderr=STDOUT)
#The output will be "HTTP/1.1 200 OK", "HTTP/1.0 200 OK" OR "HTTP/2.0 200 OK"
for line in iter(p.stdout.readline, b''):
    if line.rstrip().startswith('HTTP/') and line.rstrip().endswith('200 OK'):
        print '\nFOUND IT: ' + line.rstrip()
        wifi_flag = True
        break

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM