当前位置: 首页>>代码示例>>Python>>正文


Python socket.IPPROTO_RAW属性代码示例

本文整理汇总了Python中socket.IPPROTO_RAW属性的典型用法代码示例。如果您正苦于以下问题:Python socket.IPPROTO_RAW属性的具体用法?Python socket.IPPROTO_RAW怎么用?Python socket.IPPROTO_RAW使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在socket的用法示例。


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

示例1: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def __init__(self, type=ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):  # noqa: E501
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)  # noqa: E501
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))  # noqa: E501
        self.iface = iface
        if iface is not None:
            self.ins.bind((self.iface, type))
        if not six.PY2:
            try:
                # Receive Auxiliary Data (VLAN tags)
                self.ins.setsockopt(SOL_PACKET, PACKET_AUXDATA, 1)
                self.ins.setsockopt(
                    socket.SOL_SOCKET,
                    SO_TIMESTAMPNS,
                    1
                )
                self.auxdata_available = True
            except OSError:
                # Note: Auxiliary Data is only supported since
                #       Linux 2.6.21
                msg = "Your Linux Kernel does not support Auxiliary Data!"
                log_runtime.info(msg) 
开发者ID:secdev,项目名称:scapy,代码行数:24,代码来源:supersocket.py

示例2: send

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def send(ip, tcp, payload="", retry=1, timeout=1):
    if timeout <= 0:
        # Avoid entering an infinite waiting loop
        timeout = 0.1
    response = []
    event = threading.Event()
    sock = socket.socket(socket.AF_INET,
                         socket.SOCK_RAW,
                         socket.IPPROTO_RAW)
    # Extracting identifiers
    # ip
    src = ip.source
    dst = ip.destination
    # port
    srcp = struct.pack("!H", tcp.srcp)
    dstp = struct.pack("!H", tcp.dstp)

    tcp.payload = payload
    packet = ip.pack() + tcp.pack(ip.source, ip.destination) + payload

    for i in range(retry):
        t = threading.Thread(target=recv,
                             args=(event, src, dst, srcp,
                                   dstp, response, timeout)
                             )
        t.start()
        try:
            sock.sendto(packet, (socket.inet_ntoa(dst), 0))
        except Exception as e:
            print e
        event.set()
        t.join()
        if not event.isSet():
            break

    if event.isSet():
        return None
    else:
        return response[0] 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:41,代码来源:packet.py

示例3: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        if iface is not None:
            self.ins.bind((iface, type)) 
开发者ID:medbenali,项目名称:CyberScan,代码行数:8,代码来源:supersocket.py

示例4: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def __init__(self, type = ETH_P_IPV6, filter=None, iface=None, promisc=None, nofilter=0):
        L3RawSocket.__init__(self, type, filter, iface, promisc)
        # NOTE: if fragmentation is needed, it will be done by the kernel (RFC 2292)
        self.outs = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) 
开发者ID:medbenali,项目名称:CyberScan,代码行数:7,代码来源:inet6.py

示例5: send

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def send(self, hosts, srcp, gen):
		if 'ppp' in self.ifname:
			family = socket.AF_INET
			proto = socket.IPPROTO_RAW
			eth = ''
		else:
			family = socket.AF_PACKET
			proto = ETH_P_IP
			eth = ethernet.ETHER(mac2byte(self.smac), mac2byte(self.dmac), ETH_P_IP).pack()
		sock = socket.socket(family, socket.SOCK_RAW, proto)
		transport = self.__Transport(srcp, 0)
		npacket = 0
		self.events['send'].wait()
		target = hosts[0]
		while self.events['send'].isSet():
			try:
				target = hosts[0] + gen.next()
				iph = ip.IP(self.diface, dec2dot(target), self.stype)
			except StopIteration:
				break
			for port_list in self.ports:
				for port in range(port_list[0], port_list[1]):
					if self.events['send'].isSet():
						transport.dstp = port
						packet = eth + iph.pack() + self.__Pack(transport, iph.src, iph.dst) #tcph.pack(iph.src, iph.dst)
						sock.sendto(packet, (dec2dot(target), 0)) # self.ifname
						npacket+=1
						if not npacket%self.cooldown[0]:
							time.sleep(self.cooldown[1])
					else:
						break
		logging.info('[SEND] Sent: {} packets'.format(npacket))
		sock.close() 
开发者ID:OffensivePython,项目名称:Nscan,代码行数:35,代码来源:probe.py

示例6: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def __init__(self, daddr):
        try:
            self.raw_sock = socket.socket(
                socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW
            )
        except PermissionError as e:
            print(e)
            print("Please run as root!")
            exit(1)
        self.ip_daddr = daddr
        os_release = platform.system()
        if os_release == "Darwin":
            # Boned. TODO: Work on fixing this.
            print("Detected Mac OS - Cannot support writing of raw IP packets, exiting")
            exit(1)
        if os_release.endswith("BSD"):
            # BSD - Need to explicit set IP_HDRINCL.
            # BSD - Need to explicitly calculate IP total length
            self.raw_sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
            logging.debug("Detected a BSD")
        if os_release == "Linux":
            # Linux - No need to set IP_HDRINCL,as setting SOCK_RAW auto sets this. However should be explicit in settings.
            self.raw_sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
            logging.debug("Detected Linux")
        if os_release == "Windows":
            # No idea - No ability to test. Maybe abort?
            # TODO: Find testers?
            logging.debug("Detected NT")
            print("Untested on Windows - Exiting")
            exit(1) 
开发者ID:rucarrol,项目名称:traceflow,代码行数:32,代码来源:socket_handler.py

示例7: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def __init__(self, type = ETH_P_IP, filter=None, iface=None, promisc=None, nofilter=0):
        self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
        self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1)
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) 
开发者ID:RiskSense-Ops,项目名称:CVE-2016-6366,代码行数:6,代码来源:supersocket.py

示例8: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def __init__(self, type=ETH_P_IPV6, filter=None, iface=None, promisc=None, nofilter=0):  # noqa: E501
        L3RawSocket.__init__(self, type, filter, iface, promisc)
        # NOTE: if fragmentation is needed, it will be done by the kernel (RFC 2292)  # noqa: E501
        self.outs = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_RAW)  # noqa: E501
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))  # noqa: E501 
开发者ID:secdev,项目名称:scapy,代码行数:7,代码来源:inet6.py

示例9: test_getprotobyname

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def test_getprotobyname(self):
        '''Tests _socket.getprotobyname'''
        #IP and CPython
        proto_map = {
                    "icmp": _socket.IPPROTO_ICMP,
                    "ip": _socket.IPPROTO_IP,
                    "tcp": _socket.IPPROTO_TCP,
                    "udp": _socket.IPPROTO_UDP,
        }

        #supported only by IP
        if is_cli:
            proto_map.update(
                {"dstopts": _socket.IPPROTO_DSTOPTS,
                "none": _socket.IPPROTO_NONE,
                "raw": _socket.IPPROTO_RAW,
                "ipv4": _socket.IPPROTO_IPV4,
                "ipv6": _socket.IPPROTO_IPV6,
                "esp": _socket.IPPROTO_ESP,
                "fragment": _socket.IPPROTO_FRAGMENT,
                "nd": _socket.IPPROTO_ND,
                "icmpv6": _socket.IPPROTO_ICMPV6,
                "routing": _socket.IPPROTO_ROUTING,
                "pup": _socket.IPPROTO_PUP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
                "ggp": _socket.IPPROTO_GGP, #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=21918
                })

        for proto_name, good_val in proto_map.items():
            temp_val = _socket.getprotobyname(proto_name)
            self.assertEqual(temp_val, good_val)

        #negative cases
        bad_list = ["", "blah", "i"]
        for name in bad_list:
            self.assertRaises(_socket.error, _socket.getprotobyname, name) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:37,代码来源:test__socket.py

示例10: connect

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def connect(self):
        if self._socket is not None:
            # Close out old socket first
            self._socket.close()
        # Include IP headers
        self._socket = socket.socket(socket.AF_INET,
                                     socket.SOCK_RAW,
                                     socket.IPPROTO_RAW)
        self._socket.bind((self._interface, 0))
        self._socket.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) 
开发者ID:MozillaSecurity,项目名称:peach,代码行数:12,代码来源:raw.py

示例11: udp_spoof_start

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_RAW [as 别名]
def udp_spoof_start(target_ip, target_port, spoofed_ip, spoofed_port, payload):
    """Spoof a packet and send it to target_ip, target_port.

    Keyword argument(s):
    target_ip -- the desired destination ip
    target_port -- the desired destination port
    spoofed_ip -- the desired source ip
    spoofed_port -- the desired source port
    """
    spoofed_packet = udp_spoof_pck(target_ip, target_port, spoofed_ip,
                                   spoofed_port, payload)
    sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)
    while True:
        sock.sendto(spoofed_packet, (target_ip, target_port))
        sleep(0.01) 
开发者ID:panagiks,项目名称:RSPET,代码行数:17,代码来源:rspet_client.py


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