Skip to content

Instantly share code, notes, and snippets.

@guilleJB
Last active October 30, 2024 13:16
Show Gist options
  • Save guilleJB/0d00364e3e0489daf119c8aff33a6872 to your computer and use it in GitHub Desktop.
Save guilleJB/0d00364e3e0489daf119c8aff33a6872 to your computer and use it in GitHub Desktop.
ARP on fixed IP
import subprocess
from datetime import datetime
ip_addr = 'XX.xx.xx.xx'
mac_addr = 'XX:XX:XX:XX:XX'
server_name = 'SERVER_NAME'
log_file = 'path/log'
command = 'arp {}'.format(ip_addr)
process = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
if mac_addr not in out:
with open(log_file, 'a') as f:
f.write('##### Change MAC {server_name} ####\n{date_info}\n#######\n{info}'.format(
server_name=server_name, date_info=datetime.now(), info=out)
)
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment