本文整理汇总了Python中scapy.all.sniff函数的典型用法代码示例。如果您正苦于以下问题:Python sniff函数的具体用法?Python sniff怎么用?Python sniff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sniff函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
if self.pcap:
self.parse_pcap()
else:
shownMessage = False
while not self.STOP_SNIFFING:
if self.enable_monitor_mode:
self.iface=mm.enable_monitor_mode(self.iface)
if not self.iface:
if not shownMessage:
logging.error("No suitable monitor interface available. Will check every 5 seconds, but not display this message again.")
shownMessage = True
time.sleep(5)
if not self.iface and self.enable_monitor_mode:
continue
if not self.iface:
logging.info("No interface specified. Will sniff *all* interfaces.")
else:
logging.info("Starting sniffing on interface '%s'"%self.iface)
try:
self.ready_status = True
shownMessage = False
sniff(store=0, iface=self.iface, prn=self.packeteer, filter=self.bfilter,
stopperTimeout=1, stopper=self.stopperCheck)
except Exception, e:
logging.error(("Scapy exception whilst sniffing. "
"Will back off for 5 seconds, "
"and try restart '%s' plugin") % __name__)
logging.error(e)
self.sniffErrors+=1
if self.sniffErrors >3 :
logging.error("Restarting module '%s' after 5 failed attempts" %__file__)
time.sleep(5)
开发者ID:4sp1r3,项目名称:snoopy-ng,代码行数:34,代码来源:wifi.py
示例2: sniff
def sniff(self, target=None, iface=None):
def _process(pkt):
match_ip = pkt.haslayer(IP) and (pkt[IP].src==target[0] or pkt[IP].dst==target[0]) if target else True
match_port = pkt.haslayer(TCP) and (pkt[TCP].sport==target[1] or pkt[TCP].dport==target[1]) if len(target)==2 else True
if match_ip and match_port:
self.capabilities.insert(pkt, client=False)
events = self.capabilities.get_events() # misuse get_events :/
if events:
strconn = {'src':None,
'dst':None,
'sport':None,
'dport':None}
if pkt.haslayer(IP):
strconn['src'] = pkt[IP].src
strconn['dst'] = pkt[IP].dst
if pkt.haslayer(TCP):
strconn['sport'] = pkt[TCP].sport
strconn['dport'] = pkt[TCP].dport
print "Connection: %(src)s:%(sport)d <==> %(dst)s:%(dport)d"%strconn
print "* EVENT - " + "\n* EVENT - ".join(e[0] for e in events)
return
if iface:
conf.iface=iface
while True:
bpf = None
if len(target):
bpf = "host %s"%target[0]
if len(target)==2:
bpf += " and tcp port %d"%target[1]
sniff(filter=bpf,
prn=_process,
store=0,
timeout=3)
开发者ID:ALSchwalm,项目名称:scapy-ssl_tls,代码行数:35,代码来源:security_scanner.py
示例3: main
def main():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--interface', '-i', default='mon0',
help='monitor mode enabled interface')
args = parser.parse_args()
sniff(iface=args.interface, prn=handle_packet)
开发者ID:johannestaas,项目名称:macmon,代码行数:7,代码来源:scanner.py
示例4: _sniff
def _sniff(self):
""" Wrapper for packet sniffing. """
while True:
if self._sniffing is False:
return
sniff(iface=self._wireless_interface, prn=self._process, filter=FILTER + self._mac_address, store=0,
timeout=SNIFF_TIMEOUT)
开发者ID:megfault,项目名称:aDTN-python,代码行数:7,代码来源:aDTN.py
示例5: sniff
def sniff(self):
if self.options.pcap_file == 'None':
self.logger.info("Using network interface: %s" % (self.options.listen_interface))
try:
scapy.sniff(iface = self.options.listen_interface, prn = self.pkt_callback, lfilter = self.pkt_check, filter = self.options.filter, store = 0)
except socket.error, e:
self.logger.error("Sniffer error on %s: %s" % (self.options.listen_interface, e))
开发者ID:0x0d,项目名称:wallofshame,代码行数:7,代码来源:sniffer.py
示例6: __sniff_sessionkey_and_salt__
def __sniff_sessionkey_and_salt__(self,ip=None,port=None):
'''
To sniff the session key and the salt in an Oracle connection thanks to scapy
'''
def customAction(packet):
global sessionKey, salt
if packet[0].haslayer(IP)==True and packet[1].src == ip :
#print packet.show()
if packet[2].haslayer(scapyall.Raw)==True:
raw = repr(packet[2].getlayer(scapyall.Raw).load)
if "AUTH_SESSKEY" in raw and "AUTH_VFR_DATA" in raw:
sessionKey = re.findall(r"[0-9a-fA-F]{96}" ,raw[raw.index("AUTH_SESSKEY"):raw.index("AUTH_VFR_DATA")])
if sessionKey != [] : sessionKey = sessionKey[0]
try : authVFRindex = raw.index("AUTH_VFR_DATA")
except : logging.warning("The following string doesn't contain AUTH_VFR_DATA: {0}".format(raw))
else:
try: authGloIndex = raw.index("AUTH_GLOBALLY_UNIQUE_DBID")
except : logging.warning("The following string doesn't contain AUTH_GLOBALLY_UNIQUE_DBID: {0}".format(raw))
else:
salt = re.findall(r"[0-9a-fA-F]{22}" ,raw[authVFRindex:authGloIndex])
if salt != [] : salt = salt[0][2:]
finally:
return True
return False
self.__resetSessionKeyValueAndSalt__()
#print "Run with tcp and host {0} and port {1}".format(ip,port)
scapyall.sniff(filter="tcp and host {0} and port {1}".format(ip,port), count=self.MAX_PACKET_TO_CAPTURE, timeout=self.TIMEOUT, stop_filter=customAction,store=False)
return sessionKey, salt
开发者ID:rainsome-org1,项目名称:odat,代码行数:28,代码来源:CVE_2012_3137.py
示例7: __init__
def __init__(self, listenInt, interface, freq, essid, psswd, ip, nm, discoverOnce=True):
self.robotName = os.getenv('HOSTNAME')
self.tolerance = 20
self.x = 0
self.y = 0
self.client = WiFiTrilatClient()
self.discoverOnce = discoverOnce
rospy.init_node(self.robotName + "_wifitrilat_server")
#self.rssiPub = rospy.Publisher('/' + self.robotName + '/WiFiRSSI', WiFiRSSIMsg, queue_size=10)
self.service = rospy.Service("/" + self.robotName + "/WiFiTrilat", WiFiTrilat, self.handle_Trilat)
self.listenInt = listenInt
self.interface = interface
#self.mac = mac.lower()
self.freq = int(freq)
self.msgs = []
cli.execute_shell("ifconfig %s down" % self.listenInt)
#self.wifi = Wireless(self.interface).setFrequency("%.3f" % (float(self.freq) / 1000))
self.connectToNet(essid, psswd,ip, nm)
cli.execute_shell("ifconfig %s up" % self.listenInt)
self.purge = rospy.Timer(rospy.Duration(2), self.msgPurge)
self.heartbeat = rospy.Timer(rospy.Duration(1), self.heartbeat_call)
self.discoverTimer = rospy.Timer(rospy.Duration(20), self.findSelfPos)
sniff(iface=self.listenInt, prn=self.handler, store=0)
rospy.spin()
开发者ID:superit23,项目名称:SwarmRobotics,代码行数:33,代码来源:WiFiTrilatSrv.py
示例8: run
def run(self):
"""Run the sniffer"""
try:
sniff(filter="arp", prn=self._arp_callback, store=False, stop_filter=self._stopper)
except TypeError:
print("Ok! This error likely happened because you are not using scapy version 2.2 or above")
raise
开发者ID:magne4000,项目名称:ftpvista,代码行数:7,代码来源:sniffer.py
示例9: __init__
def __init__(self):
# Parameters
interface = 'mon0'
freq = '2442 MHz' # Mhz (channel 7)
#Shared Variables
self.mac_list = [[]] # [time, mac addr, signal level]
self.white_list = [] # whitelist of mac addr
self.dt = 1 # sample time in minutes
# Init wifi
print "Init wifi..."
while(1):
try:
Wireless(interface).setMode('Monitor')
Wireless(interface).setFrequency(freq)
break
except:
os.system("sh wifi_setup.sh")
return "Wifi Initialisation failed!"
self.loadWhiteList()
# Init interrupt
sniff(iface=interface, prn=self.handler, store=0)
开发者ID:savnik,项目名称:smart_city_sensor,代码行数:25,代码来源:mac_int.py
示例10: __sniff_sessionkey_and_salt__
def __sniff_sessionkey_and_salt__(self, ip=None, port=None):
"""
To sniff the session key and the salt in an Oracle connection thanks to scapy
"""
def customAction(packet):
global sessionKey, salt
if packet[0].haslayer(IP) == True and packet[1].src == ip:
# print packet.show()
if packet[2].haslayer(scapyall.Raw) == True:
raw = repr(packet[2].getlayer(scapyall.Raw).load)
if "AUTH_SESSKEY" in raw and "AUTH_VFR_DATA" in raw:
sessionKey = re.findall(
r"[0-9a-fA-F]{96}", raw[raw.index("AUTH_SESSKEY") : raw.index("AUTH_VFR_DATA")]
)
if sessionKey != []:
sessionKey = sessionKey[0]
salt = re.findall(
r"[0-9a-fA-F]{22}", raw[raw.index("AUTH_VFR_DATA") : raw.index("AUTH_GLOBALLY_UNIQUE_DBID")]
)
if salt != []:
salt = salt[0][2:]
return True
return False
self.__resetSessionKeyValueAndSalt__()
# print "Run with tcp and host {0} and port {1}".format(ip,port)
scapyall.sniff(
filter="tcp and host {0} and port {1}".format(ip, port),
count=self.MAX_PACKET_TO_CAPTURE,
timeout=self.TIMEOUT,
stop_filter=customAction,
store=False,
)
return sessionKey, salt
开发者ID:GHubgenius,项目名称:odat,代码行数:35,代码来源:CVE_2012_3137.py
示例11: main
def main():
''' Main function '''
global log, FTP_LOG, debugMode, consoleMode, printCookies, expr, LOGFILE
log=logging.getLogger(APP_NAME)
#if consoleMode:
# handler = logging.StreamHandler()
#else:
handler = logging.FileHandler(LOGFILE)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
if debugMode==False:
log.setLevel(logging.INFO)
else:
log.setLevel(logging.DEBUG)
printMessage("Listening on "+expr)
if debugMode:
printMessage("Debug mode activated")
if consoleMode:
printMessage("Console mode activated")
else:
daemonize()
try:
sniff(filter=expr, prn=http_monitor_callback, store=0)
except KeyboardInterrupt:
exit(0)
开发者ID:houcy,项目名称:extsniff,代码行数:34,代码来源:extsniff.py
示例12: run
def run(self):
"""
Starts the kitchen.
This blocks and will run forever.
"""
# Start the chef poking thread.
if self.chef_poke_interval is not None:
self._logger.info(
"{0}: Starting interval poker thread".format(self.name))
interval_poker = Thread(
target=self._poke_chefs,
kwargs={'interval': self.chef_poke_interval}
)
interval_poker.start()
else:
self._logger.info(
"{0}: Interval poker thread disabled".format(self.name))
# Start the sniffer.
self._logger.info("{0}: Starting sniffer thread".format(self.name))
if self.interface == 'all':
sniff(filter=self.filter, prn=self._process_packet, store=0)
else:
sniff(iface=self.interface, filter=self.filter,
prn=self._process_packet, store=0)
开发者ID:mjoblin,项目名称:netdumplings,代码行数:29,代码来源:dumplingkitchen.py
示例13: main
def main():
if not len(sys.argv[1:]):
usage()
arp_watcher_db_file = "/Users/kenyadoit/Desktop/arpwatcher.db"
ip_mac = {}
#Save ARP table on shutdown
def sig_int_handler(signum, frame):
print "Got SIGINT. Saving ARP dtabase..."
try:
f = open(arp_watcher_db_file, "w")
for (ip, mac) in ip_mac.items():
f.write(ip + " " + mac + "\n")
f.close()
print "Done."
except IOError:
print "Cannot write file. YOU FUCKED IT UP AGAIN DUMMY " +_watcher_db_file
sys.exit(1)
def watch_arp(pkt):
#got is-at pkt (ARP resposne)
if pkt[ARP].op == 2:
print pkt[ARP].hwsrc + " " + pkt[ARP].psrc
#Remember new device
if ip_mac.get(pkt[ARP].psrc) == None:
print "Found new device " + \
pkt[ARP].hwsc + " " + \
pkt[ARP].psrc
ip_mac[pkt[ARP].psrc] = pkt[ARP].hwsrc
#Known device but different IP
elif ip_mac.get(pkt[ARP].psrc) and ip_mac[pkt[ARP].psrc] != pkt[ARP].hwsrc:
print pkt[ARP].hwsrc + \
" has got new ip " + \
" (old " + ip_mac[pkt[ARP].psrc] + ")"
ip_mac[pkt[ARP].psrc] = pkt[ARP].hwsrc
signal(SIGINT, sig_int_handler)
if len(sys.argv) < 2:
print sys.argv[0] + " <iface>"
sys.exit(0)
try:
fh = open(arp_watcher_db_file, "r")
except IOError:
print "Cannot read file " + arp_watcher_db_file
sys.exit(1)
for line in fh:
line.chomp()
(ip, mac) = line.split (" ")
ip_mac[ip] = mac
sniff(prn = watch_arp, filter="arp", iface=sys.argv[1], store= 0)
开发者ID:n1cfury,项目名称:Python,代码行数:59,代码来源:UNHarpwatcher.py
示例14: main
def main():
args = parse_args()
simpNetMon = SimpleNetworkMonitor(args.filename)
if args.show_known:
simpNetMon.show_known()
return
sniff(prn=simpNetMon.arp_monitor_callback, filter='arp',
store=0, iface=args.interface)
开发者ID:d1b,项目名称:mac_watcher,代码行数:8,代码来源:watcher.py
示例15: _handle_sniffing
def _handle_sniffing():
global _iface, _sniffer
print_d("sniffer started")
if _iface is None:
raise RuntimeError("no monitoring interface specified yet. call set_interface() first")
sniff(iface=_iface, store=0, stop_filter=_handle_packet)
_sniffer = None
print_d("sniffer stopped")
开发者ID:dronepwn2k16,项目名称:skyjack,代码行数:8,代码来源:asyncscapy.py
示例16: main
def main():
running = True
while running:
try:
filter = "tcp dst port 6969"
sniff(filter = filter,prn=analyse,count=10,store=0)
except KeyboardInterrupt:
running = False
开发者ID:jheise,项目名称:btdetect,代码行数:8,代码来源:btdetect.py
示例17: __call__
def __call__(cls):
from scapy.all import sniff
try:
sniff(iface=cls.iface, store=0, prn=cls._prn_)
except KeyboardInterrupt as e:
raise
except Exception as e:
print e
开发者ID:cmj0121,项目名称:AnySourceCode,代码行数:8,代码来源:hermes.py
示例18: traffic_sniffer
def traffic_sniffer(self):
""" Sniff traffic with the given filter.
If sniff_filter is not set, an exception is raised
"""
if self.sniff_filter is None:
raise NotImplementedError, "sniff_filter not initialized!"
sniff(filter=self.sniff_filter, store=0, prn=self.dump, stopper=self.stop_callback, stopperTimeout=3)
开发者ID:jorik041,项目名称:zarp,代码行数:8,代码来源:sniffer.py
示例19: _do_sniff
def _do_sniff(self, timeout=None, lfilter=None):
lfilter = lfilter or (lambda packet: True)
sniff(iface=self.interface,
prn=lambda packet: self.packet_queue.put(packet),
store=0,
lfilter=lambda packet: lfilter(packet) and packet.haslayer(Dot11),
stop_filter=lambda packet: self.stopped,
timeout=timeout)
开发者ID:lukius,项目名称:wifi-deauth,代码行数:8,代码来源:sniffer.py
示例20: run
def run(self):
"""Starts sniffing for incoming ARP packets with scapy.
Actions after receiving a packet ar defines via _packet_handler.
"""
# the filter argument in scapy's sniff function seems to be applied too late
# therefore some unwanted packets are processed (e.g. tcp packets of ssh session)
# but it still decreases the number of packets that need to be processed by the lfilter function
sniff(prn=self._packet_handler, filter=self._SNIFF_FILTER, lfilter=self._LFILTER, store=0, iface=self.interface)
开发者ID:usableprivacy,项目名称:upribox,代码行数:8,代码来源:sniff_thread.py
注:本文中的scapy.all.sniff函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论