本文整理匯總了Python中socket.IPPROTO_ICMP屬性的典型用法代碼示例。如果您正苦於以下問題:Python socket.IPPROTO_ICMP屬性的具體用法?Python socket.IPPROTO_ICMP怎麽用?Python socket.IPPROTO_ICMP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類socket
的用法示例。
在下文中一共展示了socket.IPPROTO_ICMP屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: answers
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def answers(self, other):
if not isinstance(other,IP):
return 0
if conf.checkIPaddr and (self.dst != other.src):
return 0
if ( (self.proto == socket.IPPROTO_ICMP) and
(isinstance(self.payload, ICMP)) and
(self.payload.type in [3,4,5,11,12]) ):
# ICMP error message
return self.payload.payload.answers(other)
else:
if ( (conf.checkIPaddr and (self.src != other.dst)) or
(self.proto != other.proto) ):
return 0
return self.payload.answers(other.payload)
示例2: tcp_trace
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def tcp_trace(ip, port, tr_tout, output, collect):
status = {'end': False}
rx = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
rx.setblocking(0)
rx.settimeout(tr_tout)
rx.bind(('', 0))
print('\n' + R + 'HOPS'.ljust(7) + 'IP'.ljust(17) + 'HOST' + W + '\n')
for ttl in range(1,31):
t = threading.Thread(target=tcp_send(ip, port, ttl, rx, status, tr_tout, output, collect), daemon=True)
t = t.start()
if status['end'] == True:
break
rx.close()
示例3: _open_icmp_socket
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def _open_icmp_socket(family):
"""
Opens a socket suitable for sending/receiving ICMP echo
requests/responses.
"""
try:
proto = socket.IPPROTO_ICMP if family == socket.AF_INET \
else _IPPROTO_ICMPV6
return socket.socket(family, socket.SOCK_RAW, proto)
except socket.error as e:
if e.errno == 1:
raise MultiPingError("Root privileges required for sending "
"ICMP")
# Re-raise any other error
raise
示例4: init_func
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [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
示例5: ipv4_parseable
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def ipv4_parseable(ip_header_data):
"""Return True if an IPv4 packet we could parse."""
# TODO: python library parsers are fragile
# Perform sanity checking on the header to limit exposure of the parser
ipv4_header = struct.unpack('!BBHHHBBH4s4s', ip_header_data[:IPV4_HEADER_SIZE])
header_size = (ipv4_header[0] & 0xf) * 32 / 8
if header_size < IPV4_HEADER_SIZE:
return False
flags = ipv4_header[4] >> 12
# MF bit set
if flags & 0x2:
return False
# fragment - discard
ip_off = ipv4_header[4] & 0xfff
if ip_off:
return False
# not a protocol conservatively known to parse
protocol = ipv4_header[6]
if protocol not in (socket.IPPROTO_ICMP, socket.IPPROTO_UDP, socket.IPPROTO_TCP):
return False
return True
示例6: echo_reply
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def echo_reply(vid, eth_src, eth_dst, src_ip, dst_ip, data):
"""Return an ICMP echo reply packet.
Args:
vid (int or None): VLAN VID to use (or None).
eth_src (str): Ethernet source address.
eth_dst (str): destination Ethernet MAC address.
src_ip (ipaddress.IPv4Address): source IPv4 address.
dst_ip (ipaddress.IPv4Address): destination IPv4 address.
Returns:
ryu.lib.packet.icmp: serialized ICMP echo reply packet.
"""
pkt = build_pkt_header(vid, eth_src, eth_dst, valve_of.ether.ETH_TYPE_IP)
ipv4_pkt = ipv4.ipv4(
dst=dst_ip, src=src_ip, proto=valve_of.inet.IPPROTO_ICMP)
pkt.add_protocol(ipv4_pkt)
icmp_pkt = icmp.icmp(
type_=icmp.ICMP_ECHO_REPLY, code=icmp.ICMP_ECHO_REPLY_CODE,
data=data)
pkt.add_protocol(icmp_pkt)
pkt.serialize()
return pkt
示例7: answers
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def answers(self, other):
if not isinstance(other, IP):
return 0
if conf.checkIPaddr and (self.dst != other.src):
return 0
if ((self.proto == socket.IPPROTO_ICMP) and
(isinstance(self.payload, ICMP)) and
(self.payload.type in [3, 4, 5, 11, 12])):
# ICMP error message
return self.payload.payload.answers(other)
else:
if ((conf.checkIPaddr and (self.src != other.dst)) or
(self.proto != other.proto)):
return 0
return self.payload.answers(other.payload)
示例8: serve
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def serve(self):
server_socket = None
self.serverorclient = 1
try:
common.internal_print("Starting module: {0} on {1}".format(self.get_module_name(), self.config.get("Global", "serverbind")))
server_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
if (self.os_type == common.OS_WINDOWS) or (self.os_type == common.OS_MACOSX):
common.internal_print("This module can be run in client mode only on this operating system.", -1)
self.cleanup()
return
self.comms_socket = server_socket
self.authenticated = False
self.communication_initialization()
self.communication(False)
except KeyboardInterrupt:
self.cleanup()
return
self.cleanup()
return
示例9: connect
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def connect(self):
try:
common.internal_print("Starting client: {0}".format(self.get_module_name()))
server_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
if self.os_type == common.OS_WINDOWS:
# this should give back the default route interface IP
default_host_ip = socket.gethostbyname(socket.gethostname())
server_socket.bind((default_host_ip, 0))
self.server_tuple = (self.config.get("Global", "remoteserverip"), self.ICMP_fake_serverport)
self.comms_socket = server_socket
self.serverorclient = 0
self.authenticated = False
self.communication_initialization()
self.do_hello()
self.communication(False)
except KeyboardInterrupt:
self.do_logoff()
self.cleanup()
raise
self.cleanup()
return
示例10: check
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def check(self):
try:
common.internal_print("Checking module on server: {0}".format(self.get_module_name()))
server_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
if self.os_type == common.OS_WINDOWS:
# this should give back the default route interface IP
default_host_ip = socket.gethostbyname(socket.gethostname())
server_socket.bind((default_host_ip, 0))
self.server_tuple = (self.config.get("Global", "remoteserverip"), self.ICMP_fake_serverport)
self.comms_socket = server_socket
self.serverorclient = 0
self.authenticated = False
self.communication_initialization()
self.do_check()
self.communication(True)
except KeyboardInterrupt:
self.cleanup()
raise
except socket.timeout:
common.internal_print("Checking failed: {0}".format(self.get_module_name()), -1)
self.cleanup()
return
示例11: sniffer_thread
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [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)
示例12: hashret
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def hashret(self):
if ( (self.proto == socket.IPPROTO_ICMP)
and (isinstance(self.payload, ICMP))
and (self.payload.type in [3,4,5,11,12]) ):
return self.payload.payload.hashret()
else:
if conf.checkIPsrc and conf.checkIPaddr:
return strxor(inet_aton(self.src),inet_aton(self.dst))+struct.pack("B",self.proto)+self.payload.hashret()
else:
return struct.pack("B", self.proto)+self.payload.hashret()
示例13: udp_trace
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def udp_trace(ip, port, tr_tout, output, collect):
status = {'end': False}
rx = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
rx.setblocking(0)
rx.settimeout(tr_tout)
rx.bind(('', port))
print('\n' + R + 'HOPS'.ljust(7) + 'IP'.ljust(17) + 'HOST' + W + '\n')
for ttl in range(1, 31):
udp_send(ip, port, ttl, rx, status, tr_tout, output, collect)
if status['end'] == True:
break
rx.close()
示例14: hashret
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def hashret(self):
if ((self.proto == socket.IPPROTO_ICMP) and
(isinstance(self.payload, ICMP)) and
(self.payload.type in [3, 4, 5, 11, 12])):
return self.payload.payload.hashret()
if not conf.checkIPinIP and self.proto in [4, 41]: # IP, IPv6
return self.payload.hashret()
if self.dst == "224.0.0.251": # mDNS
return struct.pack("B", self.proto) + self.payload.hashret()
if conf.checkIPsrc and conf.checkIPaddr:
return (strxor(inet_pton(socket.AF_INET, self.src),
inet_pton(socket.AF_INET, self.dst)) +
struct.pack("B", self.proto) + self.payload.hashret())
return struct.pack("B", self.proto) + self.payload.hashret()
示例15: answers
# 需要導入模塊: import socket [as 別名]
# 或者: from socket import IPPROTO_ICMP [as 別名]
def answers(self, other):
if not conf.checkIPinIP: # skip IP in IP and IPv6 in IP
if self.proto in [4, 41]:
return self.payload.answers(other)
if isinstance(other, IP) and other.proto in [4, 41]:
return self.answers(other.payload)
if conf.ipv6_enabled \
and isinstance(other, scapy.layers.inet6.IPv6) \
and other.nh in [4, 41]:
return self.answers(other.payload)
if not isinstance(other, IP):
return 0
if conf.checkIPaddr:
if other.dst == "224.0.0.251" and self.dst == "224.0.0.251": # mDNS # noqa: E501
return self.payload.answers(other.payload)
elif (self.dst != other.src):
return 0
if ((self.proto == socket.IPPROTO_ICMP) and
(isinstance(self.payload, ICMP)) and
(self.payload.type in [3, 4, 5, 11, 12])):
# ICMP error message
return self.payload.payload.answers(other)
else:
if ((conf.checkIPaddr and (self.src != other.dst)) or
(self.proto != other.proto)):
return 0
return self.payload.answers(other.payload)