Advertisement
YJesus

Untitled

Feb 11th, 2013
1,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import logging
  2. logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  3. from scapy.all import *
  4. from time import time, sleep
  5.  
  6. conf.verb = 0
  7.  
  8. dhcpserversinit = []
  9. dhcpservers = []
  10.  
  11. init = 1
  12.  
  13. fam, hw = get_if_raw_hwaddr(conf.iface)
  14.  
  15. def dhcp_callback(pkt):
  16.    
  17.     if DHCP in pkt and pkt[DHCP].options[0][1] == 2:
  18.     if init == 1:
  19.         dhcpserversinit.append(pkt[IP].src)
  20.     else:
  21.         dhcpservers.append(pkt[IP].src)
  22.        
  23. dhcp_request = (
  24.     Ether(dst='ff:ff:ff:ff:ff:ff') /
  25.     IP(src='0.0.0.0', dst='255.255.255.255') /
  26.     UDP(sport=68, dport=67) /
  27.     BOOTP(chaddr=hw) /
  28.     DHCP(options=[('message-type', 'discover'), 'end'])
  29. )
  30.  
  31. sendp(dhcp_request)
  32.  
  33. sniff(prn=dhcp_callback, store=0, count=5)
  34.  
  35. init = 0
  36.  
  37. print "Servidores DHCP Encontrados:"
  38. print "\n".join(dhcpserversinit)
  39.  
  40. while True:
  41.    
  42.     dhcp_request = (
  43.         Ether(dst='ff:ff:ff:ff:ff:ff') /
  44.         IP(src='0.0.0.0', dst='255.255.255.255') /
  45.         UDP(sport=68, dport=67) /
  46.         BOOTP(chaddr=hw) /
  47.         DHCP(options=[('message-type', 'discover'), 'end'])
  48.     )
  49.  
  50.     sendp(dhcp_request)
  51.  
  52.     sniff(prn=dhcp_callback, store=0, count=5)
  53.    
  54.     newdhcp = set(dhcpservers)
  55.     alerts= newdhcp.difference(dhcpserversinit)
  56.    
  57.     if alerts:
  58.         print "Nuevo servidor DHCP encontrado"
  59.         print "\n".join(dhcpservers)
  60.    
  61.     dhcpserversinit = dhcpservers
  62.     dhcpservers = []
  63.    
  64.     sleep(20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement