Skip to content

Instantly share code, notes, and snippets.

@thenewvu
Last active August 29, 2015 14:13
Show Gist options
  • Save thenewvu/67e93dedd23945ba438f to your computer and use it in GitHub Desktop.
Save thenewvu/67e93dedd23945ba438f to your computer and use it in GitHub Desktop.
script: re-connect the wifi automatically
import ping
import subprocess
import time
import argparse
"""
Requirements:
python 2.7.9 +
pip
pip install ping
run as administrator
Run with --help for usage.
"""
if __name__ == "__main__":
argparse = argparse.ArgumentParser()
argparse.add_argument(
"--hotspot",
default = "Long",
help = "The hotspot's name.",
type=str)
argparse.add_argument(
"--interval",
default = 5,
help = "Check each @interval seconds.",
type=int)
args = argparse.parse_args()
hotspot = args.hotspot
interval = args.interval
while True:
print("# Ping kenh14.vn ...")
percent_lost, max_time, avg_time = ping.quiet_ping(dest_addr = "kenh14.vn")
if percent_lost > 50:
print("# Reconnecting ...")
subprocess.check_call("netsh wlan connect name={hotspot}".format(hotspot = hotspot))
time.sleep(interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment