Skip to content
Snippets Groups Projects
Commit 3fffe620 authored by Hendrik Buschmeier's avatar Hendrik Buschmeier
Browse files
parents 5cd9b202 07ebd969
No related branches found
No related tags found
No related merge requests found
...@@ -30,12 +30,17 @@ ...@@ -30,12 +30,17 @@
# Forschungsgemeinschaft (DFG) in the context of the German # Forschungsgemeinschaft (DFG) in the context of the German
# Excellence Initiative. # Excellence Initiative.
from __future__ import print_function
import logging import logging
import re
import sys import sys
import time import time
import ipaaca import ipaaca
color = False color = False
regex = False
max_size = 2048 max_size = 2048
def highlight_if_color(s, c='1'): def highlight_if_color(s, c='1'):
...@@ -62,11 +67,16 @@ def pretty_printed_iu_event(iu, event_type, local): ...@@ -62,11 +67,16 @@ def pretty_printed_iu_event(iu, event_type, local):
return s return s
def my_update_handler(iu, event_type, local): def my_update_handler(iu, event_type, local):
if regex:
for cat in cats: # actually now regexs, not cats
if re.match(cat, iu.category):
break
else:
return
t=time.localtime() t=time.localtime()
print pretty_printed_iu_event(iu, event_type, local) print(pretty_printed_iu_event(iu, event_type, local))
cats = [] cats = []
keep_going=True keep_going=True
idx = 1 idx = 1
while keep_going: while keep_going:
...@@ -76,11 +86,15 @@ while keep_going: ...@@ -76,11 +86,15 @@ while keep_going:
print(' '+sys.argv[0]+' [--options] [<category1> [<category2 ...]]') print(' '+sys.argv[0]+' [--options] [<category1> [<category2 ...]]')
print(' Listen to specified categories (default: all)') print(' Listen to specified categories (default: all)')
print(' Option --color : colorize output') print(' Option --color : colorize output')
print(' Option --regex : match categories by regular expressions')
print(' Option --size-limit <size> : limit payload display, chars (def: 2048)') print(' Option --size-limit <size> : limit payload display, chars (def: 2048)')
sys.exit(0) sys.exit(0)
elif opt=='--color': elif opt=='--color':
color = True color = True
idx += 1 idx += 1
elif opt=='--regex':
regex = True
idx += 1
elif opt=='--size-limit': elif opt=='--size-limit':
if len(sys.argv)<idx+2: if len(sys.argv)<idx+2:
print('Please specify a max size') print('Please specify a max size')
...@@ -91,13 +105,22 @@ while keep_going: ...@@ -91,13 +105,22 @@ while keep_going:
cats = sys.argv[idx:] cats = sys.argv[idx:]
keep_going = False keep_going = False
ib = ipaaca.InputBuffer('SnifferIn', [''] if len(cats)==0 else cats)
ib = ipaaca.InputBuffer('SnifferIn', [''] if (len(cats) == 0 or regex) else cats)
ib.register_handler(my_update_handler) ib.register_handler(my_update_handler)
print('') print('')
print('Ipaaca IU Sniffer - run with --help to see options') print('Ipaaca IU Sniffer - run with --help to see options')
print('Listening for IU events of '+('any category...' if len(cats)==0 else 'categories: '+' '.join(cats))) print('Listening for IU events of ', end='')
if len(cats) == 0:
print('any category ...')
else:
if regex:
print('whose category matches one of the regexes:')
else:
print('categories:')
for cat in cats:
print('\t' + cat)
print('') print('')
while True: while True:
time.sleep(1) time.sleep(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment