some simple examples with scapy

This commit is contained in:
Mari Wahl 2014-12-23 17:59:03 -05:00
parent a1bbf061c1
commit ffb92e0614
5 changed files with 72 additions and 15 deletions

View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
__author__ = "bt3"
from scapy.all import *
output=sr(IP(dst='google.com')/ICMP())
print '\nOutput is:'
print output
result, unanswered=output
print '\nResult is:'
print result[0]

View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
__author__ = "bt3"
from scapy.all import *
print conf.route
conf.route.add(host='192.168.118.2', gw='192.168.1.114')
print conf.route
conf.route.resync()
print conf.route

View File

@ -0,0 +1,10 @@
#!/usr/bin/env python
__author__ = "bt3"
from scapy.all import *
packet = IP(dst="192.168.1.114")/ICMP()/"Helloooo!"
#send(packet, loop=1)
send(packet)
packet.show()

View File

@ -0,0 +1,4 @@
#!/usr/bin/env python
__author__ = "bt3"

View File

@ -1,16 +1,31 @@
#!/usr/bin/env python
__author__ = "bt3"
from scapy.all import * from scapy.all import *
hostname = "google.com"
for i in range(1, 28): HOST = "google.com"
pkt = IP(dst=hostname, ttl=i) / UDP(dport=33434)
def traceroute():
for i in range(1, 28):
pkt = IP(dst=HOST, ttl=i) / UDP(dport=33434)
# Send the packet and get a reply # Send the packet and get a reply
reply = sr1(pkt, verbose=0) reply = sr1(pkt, verbose=0)
if reply is None: if reply is None:
# No reply =( # No reply =(
break break
elif reply.type == 3: elif reply.type == 3:
# We've reached our destination # We've reached our destination
print "Done!", reply.src print "Done!", reply.src
break break
else: else:
# We're in the middle somewhere # We're in the middle somewhere
print "%d hops away: " % i , reply.src print "%d hops away: " % i , reply.src
if __name__ == '__main__':
traceroute()