Skip to content

Instantly share code, notes, and snippets.

@arnav-kr
Last active February 12, 2024 10:44
Show Gist options
  • Select an option

  • Save arnav-kr/92287eff77e43cf31a6e11ac2ea7a12c to your computer and use it in GitHub Desktop.

Select an option

Save arnav-kr/92287eff77e43cf31a6e11ac2ea7a12c to your computer and use it in GitHub Desktop.
Phone IP Sync Script for Task Scheduler on Windows

Important

Prerequisite: make sure nmap is installed for windows and in path, Download if not already installed

Note

Make sure set the user account to Administrators, else the script won't be able to modify the hosts file

Youtube Demo: https://youtu.be/JxQjdxpGU5g

General Properties:

General Properties

Triger:

Trigger Properties

Actions:

Actions Properties
#! /usr/bin/python
import subprocess, ctypes
def popup(text="", title="Phone IP Sync", style=0):
return ctypes.windll.user32.MessageBoxW(0, text, title, style)
result = subprocess.run(["arp", "-a"], capture_output=True, text=True).stdout
ips = [ip.split()[0] for ip in result.splitlines() if "dynamic" in ip]
print(ips[0])
if not len(ips):
popup("Phone IP not found.\t\t", "Phone IP Sync", 0)
exit(1)
# edit hosts file (Windows)
with open("C:\\Windows\\System32\\drivers\\etc\\hosts", "r+") as hosts:
lines = [line for line in hosts if "phone" not in line]
hosts.seek(0)
hosts.truncate()
lines.append(f"{ips[0]} phone\n")
hosts.writelines(lines)
popup("Phone IP synced successfully.\t\t", "Phone IP Sync", 0)
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment