Skip to content

Instantly share code, notes, and snippets.

@mpoerwito
Created November 11, 2022 01:07
Show Gist options
  • Save mpoerwito/f64765b5313ae30d443aa13b8fba59d3 to your computer and use it in GitHub Desktop.
Save mpoerwito/f64765b5313ae30d443aa13b8fba59d3 to your computer and use it in GitHub Desktop.
check ARP table for duplicate entries. final project
import os
import platform
from datetime import datetime
def filterARP():
arptable_file = "data/table.txt"
lines = []
MACaddrs = []
ip2mac = {}
os.system(f"arp -a > {arptable_file}")
with open(arptable_file, "r") as file:
for line in file:
l = line.strip()
ip = ""
macaddr = ""
if platform.system() == "Windows":
if l[:1] != "I" and l[:1] != "":
lines.append(l[:43])
ip = l[:21].strip()
macaddr = l[22:43].strip()
else: # linux/mac arp table
arr = l.split(" ")
ip = arr[1].replace("(", "").replace(")", "")
macaddr = arr[3]
if macaddr != "" and macaddr[:5] != "ff-ff":
ip2mac[ip] = macaddr
MACaddrs.append(macaddr)
# return MACaddrs
return ip2mac
def dupeCheck(maclist):
addrs = []
dupefound = False
maclist = list(maclist.values())
for a in maclist:
if a not in addrs:
addrs.append(a)
else:
dupefound = True
save2Log(a)
if dupefound:
print("You got dupes. Check log.")
else:
print("ARP table looks good.")
def save2Log(address):
now = datetime.now() #.strftime("%Y-%m-%d %H:%M:%S")
with open("data/spoofed.log", "a") as logfile:
logfile.write(f"ARP Spoofed!\nThe address is:{address}\nDate: {now}\n")
def main():
arp_addrs = filterARP()
# check filtered ARP
for k in arp_addrs.keys():
print(f"{k}\t\t-> {arp_addrs[k]}")
dupeCheck(arp_addrs)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment