Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Last active May 16, 2022 08:22
Show Gist options
  • Save thewh1teagle/267e8ad2982152e4637cc00165f561f0 to your computer and use it in GitHub Desktop.
Save thewh1teagle/267e8ad2982152e4637cc00165f561f0 to your computer and use it in GitHub Desktop.
import subprocess
import sys
def ip_of_mac(mac):
mac = mac.lower().replace(":", "-")
output = str (
subprocess.check_output((f'arp -a | findstr "{mac}" '), shell=True, stderr=subprocess.STDOUT)
)
if len(output) <= 125 and len(output) > 5:
return output.split(' ',1)[1].split(' ')[1]
else:
return "Not found"
if __name__ == '__main__':
if len(sys.argv) < 2 or any('help' in i for i in sys.argv):
print("Usage: {} <aa-bb-cc-dd-ee-ff>".format(sys.argv[0]))
exit(1)
try:
ip = ip_of_mac(sys.argv[1])
print(ip)
except:
print("Not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment