• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python all.srp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scapy.all.srp函数的典型用法代码示例。如果您正苦于以下问题:Python srp函数的具体用法?Python srp怎么用?Python srp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了srp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
  param = getparam(1)
  ping =  Ether() / IP(dst=param) / ICMP()
  if ping['Ethernet'].dst=="ff:ff:ff:ff:ff:ff":
    print "It seems that the host did'nt answer to arp"
    sys.exit(1)
  print ("Ready to sent icmp to %s @ %s" % (ping['Ethernet'].dst, ping['IP'].dst))
  print "Pinging with real MAC...",
  sys.stdout.flush()
  rep,non_rep = srp(ping ,timeout=5,verbose=0)
  if rep:
    print "Got answer...\nTrying with other sources"
    MAC1 = "00:0c:29"
    for I in range(2,16):
      ping =  Ether(src=MAC1+macr()+macr()+macr()) / IP(dst=param) / ICMP()
      rep,non_rep = srp(ping ,timeout=5,verbose=0)
      if rep:
        print ("%s pass; %i Mac address allowed" % (ping['Ethernet'].src, I))
      else:
        print ("Mmmm... Didn't answer anymore Security allow %i Mac" % I)
        sys.exit(1)
  else:
    print "The host did'nt answer"
    sys.exit(1)
  print "No port security in place"
开发者ID:Roywaller,项目名称:Chall_Tools,代码行数:25,代码来源:test_portsec.py


示例2: arp_spoof

def arp_spoof(fake_ip, mac_address):
    try:
        for _ in xrange(5):
            srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(psrc=fake_ip, hwsrc=mac_address), verbose=0, timeout=0.05)
            time.sleep(0.05)
    except socket.error:
        # Are you sure you're running as root?
        print "ERROR: You need to run this script as root."
        sys.exit()
开发者ID:nadirs,项目名称:teeceepee,代码行数:9,代码来源:curl.py


示例3: ARPGenerator

def ARPGenerator(destIP, srcMAC='random'):
    '''Procedure to generate multiple ARP Packets '''
    print "Thread ARP Generator started"
    try:
        if srcMAC == 'self':
            for _ in range(FLOODPACKETCOUNT):
                ans, unans = srp(Ether(dst=BROADCASTMAC)/ARP(pdst=destIP), timeout=1, inter=0.1)
        else:
            if srcMAC == 'random':
                srcMAC = randomMAC()
            for _ in range(FLOODPACKETCOUNT):
                ans, unans = srp(Ether(dst=BROADCASTMAC, src=srcMAC)/ARP(hwsrc=srcMAC, pdst=destIP), timeout=1, inter=0.1)
    except Exception as e:
        print "Exception occurred: ", e
开发者ID:onfsdn,项目名称:DELTA,代码行数:14,代码来源:util.py


示例4: icmp_ping

def icmp_ping(ip, mac=None):

    if ip is None:
        return (None, None)

    if mac is None:
        ans, unans = srp(Ether() / IP(dst=ip) / ICMP(), timeout=2)
    else:
        ans, unans = srp(Ether(dst=mac) / IP(dst=ip) / ICMP(), timeout=2)

    if verbose:
        print "icmp_ping: ", ip, " ans = ", len(ans), ", unans = ", len(unans)
        sys.stdout.flush()
    return ans, unans
开发者ID:ramaekle,项目名称:test,代码行数:14,代码来源:scapy-watch.py


示例5: do_udp

def do_udp():
    """spam out some random UDP broadcasts"""

    nic = socket.gethostname() + '_0'

    while True:    
        rnd = random.uniform(5,10)
        time.sleep(rnd)
        payload = '12345678' + str(rnd)
        #build and send the packet
        srp(Ether(dst='ff:ff:ff:ff:ff:ff')/
            IP(dst="255.255.255.255")/
            UDP(sport=9898,dport=9898)/
            payload,timeout=0.001,
            iface=nic)
开发者ID:ret2kw,项目名称:testing_lab,代码行数:15,代码来源:start_vic.py


示例6: main

def main():
    """
        Entry point
    """
    # Parsing command line
    parser = OptionParser()
    parser.add_option("-t", "--timeout", type="float", dest="timeout",
                      default=1,
                      help="timeout in seconds for waiting answers",
                      metavar="TIME")
    (options, args) = parser.parse_args()

    conf.checkIPaddr = False
    fam, hw = get_if_raw_hwaddr(conf.iface)
    mac = ":".join(map(lambda x: "%.02x" % ord(x), list(hw)))
    print 'Requesting DHCP servers for', mac
    ether = Ether(dst="ff:ff:ff:ff:ff:ff", src=hw)
    ip = IP(src="0.0.0.0", dst="255.255.255.255")
    udp = UDP(sport=68, dport=67)
    bootp = BOOTP(chaddr=hw)
    dhcp = DHCP(options=[("message-type", "discover"), "end"])
    dhcp_discover = ether / ip / udp / bootp / dhcp
    ans, unans = srp(dhcp_discover, multi=True, timeout=options.timeout)
    print 'Discovered DHCP servers:'
    for p in ans:
        print p[1][Ether].src, p[1][IP].src
开发者ID:nuald,项目名称:DHCP-Explorer,代码行数:26,代码来源:dhcpexplorer.py


示例7: do_update

def do_update():
    global my_ip, my_mac, router_ip, router_mac
    get_data = Ether()/ARP(op = 1, ptype = 0x800, hwlen = 6, plen = 4)
    my_ip = get_data[ARP].psrc
    my_mac = get_data[Ether].src
    index = my_ip.rfind(".")
    router_ip = my_ip[:index+2]
    try:
        router_data = srp(Ether(src=my_mac)/ARP(op = 1, ptype = 0x800, hwlen = 6, plen = 4, pdst=router_ip), timeout=6)
    except Exception as prablm:
        exit(str(prablm) + "\n[Info] you need to be root")

    if len(router_data[0]) == 0:
        print "Got No ARP Answer From %s" % router_ip
        try:
            router_mac = str(raw_input("Specify an Router MAC Address : "))
        except Exception as problm:
            exit(problm)
        except:
            exit()
        if not router_mac:
            exit("No Router MAC Address Specified")
    else:
        try:
            router_mac = router_data[0][0][0].dst
        except Exception as sec_problm:
            exit(sec_problm)
    del router_data
    del get_data
    del index
开发者ID:st4n1,项目名称:src,代码行数:30,代码来源:mitm.py


示例8: run

    def run(self):
        conf.verb = 0
        self.console.info("sending arping...")
        ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=self.network.value), timeout=2)

        self.console.info("done")
        rows, columns = (-1, -1)
        split_input = True
        try:
            # Get the size of the window. We really only care about the rows -
            # this is used for formatting large amounts of data
            rows, columns = os.popen("stty size", "r")
        except Exception:
            self.console.warn("couldn't get the terminal window size - " + "printing without formatting.")
            time.sleep(2)
            split_input = False

        counter = 0
        for snd, rcv in ans:
            if counter == 0:
                self.console.writeln("MAC\t\t\tIP")
                counter += 1
            elif counter == rows and split_input:
                # TODO: Make this more framework-friendly
                raw_input("Press any key to continue.")
                counter = 0
            self.console.writeln(rcv.sprintf("%Ether.src%\t%ARP.psrc%"))
            counter += 1
开发者ID:rhaps0dy,项目名称:pyterpreter,代码行数:28,代码来源:arping.py


示例9: main

def main():
	"""
	Fonction principale du démon tipmac. Elle attend des connexions
	entrantes lui demandant d'établir la correspondance IP/MAC.
	"""

	HOST=''
	PORT=1337

	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.bind((HOST, PORT))
	s.listen(1)
	while 1 :
		conn, addr = s.accept()
		data = conn.recv(1024)
		print data
		ip = IPy.IP(data).strNormal()
		ans,unans = scapy.srp(scapy.Ether(dst="ff:ff:ff:ff:ff:ff")/scapy.ARP(pdst=ip),timeout=2)
		try :
			a  = ans[0][1].sprintf("%src%")
		except :
			a = "fail"

		conn.send(a)
		conn.close()
开发者ID:Retenodus,项目名称:Maiznet,代码行数:25,代码来源:tipmac.py


示例10: cmd_arp_ping

def cmd_arp_ping(ip, iface, verbose):
    """
    Send ARP packets to check if a host it's alive in the local network.

    Example:

    \b
    # habu.arp.ping 192.168.0.1
    Ether / ARP is at a4:08:f5:19:17:a4 says 192.168.0.1 / Padding
    """

    if verbose:
        logging.basicConfig(level=logging.INFO, format='%(message)s')

    conf.verb = False

    if iface:
        conf.iface = iface

    res, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip), timeout=2)

    for _, pkt in res:
        if verbose:
            print(pkt.show())
        else:
            print(pkt.summary())
开发者ID:portantier,项目名称:habu,代码行数:26,代码来源:cmd_arp_ping.py


示例11: check_dhcp_request

def check_dhcp_request(iface, server, range_start, range_end, timeout=5):
    """Provide interface, server endpoint and pool of ip adresses
        Should be used after offer received
        >>> check_dhcp_request('eth1','10.10.0.5','10.10.0.10','10.10.0.15')
    """

    scapy.conf.iface = iface

    scapy.conf.checkIPaddr = False

    fam, hw = scapy.get_if_raw_hwaddr(iface)

    ip_address = next(utils.pick_ip(range_start, range_end))

    # note lxc dhcp server does not respond to unicast
    dhcp_request = (scapy.Ether(src=hw, dst="ff:ff:ff:ff:ff:ff") /
                    scapy.IP(src="0.0.0.0", dst="255.255.255.255") /
                    scapy.UDP(sport=68, dport=67) /
                    scapy.BOOTP(chaddr=hw) /
                    scapy.DHCP(options=[("message-type", "request"),
                                        ("server_id", server),
                                        ("requested_addr", ip_address),
                                        "end"]))
    ans, unans = scapy.srp(dhcp_request, nofilter=1, multi=True,
                           timeout=timeout, verbose=0)
    return ans
开发者ID:Axam,项目名称:nsx-web,代码行数:26,代码来源:api.py


示例12: scan

def scan():
	try:
		print(colors.blue+"interfaces:"+colors.end)
		for iface in netifaces.interfaces():
			print(colors.yellow+iface+colors.end)
		print("")
		interface = input(colors.purple+"interface: "+colors.end)
		try:
			ip = netifaces.ifaddresses(interface)[2][0]['addr']
		except(ValueError, KeyError):
			printError("invalid interface")
			return
		ips = ip+"/24"
		printInfo("scanning please wait...\n", start="\n")
		print(colors.blue+"MAC - IP"+colors.end)

		start_time = datetime.now()

		conf.verb = 0
		try:
			ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst = ips), timeout = 2,iface=interface,inter=0.1)
		except PermissionError:
			printError('root permissions required')
			return

		for snd,rcv in ans:
			print(rcv.sprintf(colors.yellow+"r%Ether.src% - %ARP.psrc%"+colors.end))
		stop_time = datetime.now()
		total_time = stop_time - start_time
		printSuccess("scan completed", start="\n")
		printSuccess("scan duration: "+str(total_time))
	except KeyboardInterrupt:
		printInfo("network scanner terminated", start="\n")
开发者ID:4shadoww,项目名称:usploit,代码行数:33,代码来源:network_scanner.py


示例13: cmd_dhcp_discover

def cmd_dhcp_discover(iface, timeout, verbose):
    """Send a DHCP request and show what devices has replied.

    Note: Using '-v' you can see all the options (like DNS servers) included on the responses.

    \b
    # habu.dhcp_discover
    Ether / IP / UDP 192.168.0.1:bootps > 192.168.0.5:bootpc / BOOTP / DHCP
    """

    conf.verb = False

    if iface:
        conf.iface = iface

    conf.checkIPaddr = False

    hw = get_if_raw_hwaddr(conf.iface)

    ether = Ether(dst="ff:ff:ff:ff:ff:ff")
    ip = IP(src="0.0.0.0",dst="255.255.255.255")
    udp = UDP(sport=68,dport=67)
    bootp = BOOTP(chaddr=hw)
    dhcp = DHCP(options=[("message-type","discover"),"end"])

    dhcp_discover = ether / ip / udp / bootp / dhcp

    ans, unans = srp(dhcp_discover, multi=True, timeout=5)      # Press CTRL-C after several seconds

    for _, pkt in ans:
        if verbose:
            print(pkt.show())
        else:
            print(pkt.summary())
开发者ID:coolsnake,项目名称:habu,代码行数:34,代码来源:cmd_dhcp_discover.py


示例14: scan_lan

def scan_lan(scan_network):
    conf.verb=0
    ans,unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=scan_network),timeout=2)
    print ""
    
    log_file=strftime("%d_%b_%Y_%H:%M:%S_+0000", gmtime()) + "_-_scan.log"
    FILE = open(log_file,  "w")
    FILE.write("LAN Scanner - Log File\n")
    FILE.write("----------------------------------------\n")
    FILE.write("[+] Scanned network: " + scan_network + "\n")
    FILE.write("[+] Scan time: " + strftime("%d %b %Y, %H:%M:%S +0000 GMT", gmtime()) + "\n")
    FILE.write("\n")
    
    for snd,rcv in ans:
        mac_address=rcv.sprintf("%Ether.src%")
        ip_address=rcv.sprintf("%ARP.psrc%")
        
        print rcv.sprintf("[+] Found a system! MAC: %Ether.src% IP: %ARP.psrc% ")
        FILE.write(ip_address + ", " + mac_address + "\n")
    
    FILE.write("\n")
    FILE.close
    print ""
    print "[i] Completed the scan. Exiting now!"
    print ""
    print ""
    return
开发者ID:1989-13428,项目名称:lpd141513428,代码行数:27,代码来源:lan_scan.py


示例15: update

	def update(self):
		from scapy.all import srp,Ether,ARP,conf
		
		# Do an ARP scan of the local network
		conf.verb = 0
		ans, unans=srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=self.addr),timeout=2)

		# TODO - sort out timezones/summer time
		t = time.time()

		# Extract a list of machines and their IP addresses
		for snd,rcv in ans:
			mac = rcv.sprintf(r"%Ether.src%")
			ip = rcv.sprintf(r"%ARP.psrc%")
			if not mac in self.machines:
				self.machines.append(mac)
				self.addresses[mac] = ip
			self.names[mac] = self.get_name(mac,ip)
			self.last_seen[mac] = t

		fid = open(self.log,'wt')
		#fid.write("# "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(t))+'\n')
		# current scan time, last seen time, mac, ip
		for mac in sorted(self.last_seen,key=self.last_seen.get):
			# TODO - sort by last seen time
			fid.write(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(t))+" , "+time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(self.last_seen[mac]))+" , "+mac+" , "+self.addresses[mac]+" , "+str('%s' % float('%.1g' % (self.last_seen[mac]-t)))+" , "+self.names[mac]+'\n')
		fid.close()
开发者ID:Bisxuit,项目名称:dukebox,代码行数:27,代码来源:dukebox_scanner.py


示例16: get_arp

def get_arp(ip):
    conf.verb = 0
    ans,unans = srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip),timeout=2)
    for snd,rcv in ans:
        print('sending packet: ',snd.sprintf(r"%Ether.dst% %ARP.pdst%"),
              '\n'
              ,'\breceived packet:',rcv.sprintf(r"%ARP.psrc% %Ether.src%"))
开发者ID:icanttakeitanymore,项目名称:python_study,代码行数:7,代码来源:arp_scapy.py


示例17: check_dhcp_on_eth

def check_dhcp_on_eth(iface, timeout):
    """Check if there is roque dhcp server in network on given iface
        @iface - name of the ethernet interface
        @timeout - scapy timeout for waiting on response
    >>> check_dhcp_on_eth('eth1')
    """

    scapy.conf.iface = iface

    scapy.conf.checkIPaddr = False
    dhcp_options = [("message-type", "discover"),
                    ("param_req_list", utils.format_options(
                        [1, 2, 3, 4, 5, 6,
                         11, 12, 13, 15, 16, 17, 18, 22, 23,
                         28, 40, 41, 42, 43, 50, 51, 54, 58, 59, 60, 66, 67])),
                    "end"]

    fam, hw = scapy.get_if_raw_hwaddr(iface)
    dhcp_discover = (
        scapy.Ether(src=hw, dst="ff:ff:ff:ff:ff:ff") /
        scapy.IP(src="0.0.0.0", dst="255.255.255.255") /
        scapy.UDP(sport=68, dport=67) /
        scapy.BOOTP(chaddr=hw) /
        scapy.DHCP(options=dhcp_options))
    ans, unans = scapy.srp(dhcp_discover, multi=True,
                           nofilter=1, timeout=timeout, verbose=0)
    return ans
开发者ID:rustyrobot,项目名称:fuel-web,代码行数:27,代码来源:api.py


示例18: cmd_gateway_find

def cmd_gateway_find(network, iface, host, tcp, dport, timeout, verbose):
    """
    Try to reach an external IP using any host has a router.

    Useful to find routers in your network.

    First, uses arping to detect alive hosts and obtain MAC addresses.

    Later, create a network packet and put each MAC address as destination.

    Last, print the devices that forwarded correctly the packets.

    Example:

    \b
    # habu.find.gateway 192.168.0.0/24
    192.168.0.1 a4:08:f5:19:17:a4 Sagemcom
    192.168.0.7 b0:98:2b:5d:22:70 Sagemcom
    192.168.0.8 b0:98:2b:5d:1f:e8 Sagemcom
    """

    if verbose:
        logging.basicConfig(level=logging.INFO, format='%(message)s')

    conf.verb = False

    if iface:
        conf.iface = iface

    res, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=network), timeout=2)

    neighbors = set()

    for _, pkt in res:
        neighbors.add((pkt['Ether'].src, pkt['Ether'].psrc))

    for mac,ip in neighbors:
        if tcp:
            res, unans = srp(Ether(dst=mac)/IP(dst=host)/TCP(dport=dport), timeout=timeout)
        else:
            res, unans = srp(Ether(dst=mac)/IP(dst=host)/ICMP(), timeout=timeout)
        for _,pkt in res:
            if pkt:
                if verbose:
                    print(pkt.show())
                else:
                    print(ip, mac, conf.manufdb._get_manuf(mac))
开发者ID:portantier,项目名称:habu,代码行数:47,代码来源:cmd_gateway_find.py


示例19: arp_ping

def arp_ping(ip):
    if ip is None:
        return (None, None)
    ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip), timeout=1.5, retry=2)
    if verbose & 0x02:
        print "arp_ping: ", ip, " ans = ", len(ans), ", unans = ", len(unans)
        sys.stdout.flush()
    return (ans, unans)
开发者ID:ramaekle,项目名称:test,代码行数:8,代码来源:scapy-watch.py


示例20: tcp_ping

def tcp_ping(hosts):
    packet = Ether()/IP(dst=hosts)/TCP(dport=80, flags='S')
    ans, unans = srp(packet, filter='tcp', verbose=0, timeout=2)

    for ret in ans:
        delta = ret[1].time - ret[0].sent_time
        if ret[1][IP].src in result:
            result[ret[1][IP].src] = delta
开发者ID:Shouren,项目名称:snippet,代码行数:8,代码来源:scapy_test.py



注:本文中的scapy.all.srp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python arch.get_if_hwaddr函数代码示例发布时间:2022-05-27
下一篇:
Python all.sr1函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap