Reputation: 567
I am writing a python script to check if my android device is connected to internet. I am trying to do the following in adb shell:
The output is: - HTTP/1.0 200 OK
I care only about HTTP/1.0 200 OK, to check the internet connectivity.
I tried to use netcat in python but I don't have a very good experience to implement it.
Any help will be greatly appreciated!
Upvotes: 0
Views: 1470
Reputation: 567
Finally, the Python script is:
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
Upvotes: 2