Experimental clone attempt of http://sourceforge.net/projects/afterglow each datum is reduced as src -> event -> dst and the data are graphed. by default we have IP.src -> IP.dport -> IP.dst
(self,
src=None, # type: Optional[Callable[[_Inner], Any]]
event=None, # type: Optional[Callable[[_Inner], Any]]
dst=None, # type: Optional[Callable[[_Inner], Any]]
**kargs # type: Any
)
| 511 | return do_graph(gr, **kargs) |
| 512 | |
| 513 | def afterglow(self, |
| 514 | src=None, # type: Optional[Callable[[_Inner], Any]] |
| 515 | event=None, # type: Optional[Callable[[_Inner], Any]] |
| 516 | dst=None, # type: Optional[Callable[[_Inner], Any]] |
| 517 | **kargs # type: Any |
| 518 | ): |
| 519 | # type: (...) -> Any |
| 520 | """Experimental clone attempt of http://sourceforge.net/projects/afterglow |
| 521 | each datum is reduced as src -> event -> dst and the data are graphed. |
| 522 | by default we have IP.src -> IP.dport -> IP.dst""" |
| 523 | if src is None: |
| 524 | src = lambda *x: x[0]['IP'].src |
| 525 | if event is None: |
| 526 | event = lambda *x: x[0]['IP'].dport |
| 527 | if dst is None: |
| 528 | dst = lambda *x: x[0]['IP'].dst |
| 529 | sl = {} # type: Dict[Any, Tuple[Union[float, int], List[Any]]] |
| 530 | el = {} # type: Dict[Any, Tuple[Union[float, int], List[Any]]] |
| 531 | dl = {} # type: Dict[Any, int] |
| 532 | for i in self.res: |
| 533 | try: |
| 534 | s, e, d = src(i), event(i), dst(i) |
| 535 | if s in sl: |
| 536 | n, lst = sl[s] |
| 537 | n += 1 |
| 538 | if e not in lst: |
| 539 | lst.append(e) |
| 540 | sl[s] = (n, lst) |
| 541 | else: |
| 542 | sl[s] = (1, [e]) |
| 543 | if e in el: |
| 544 | n, lst = el[e] |
| 545 | n += 1 |
| 546 | if d not in lst: |
| 547 | lst.append(d) |
| 548 | el[e] = (n, lst) |
| 549 | else: |
| 550 | el[e] = (1, [d]) |
| 551 | dl[d] = dl.get(d, 0) + 1 |
| 552 | except Exception: |
| 553 | continue |
| 554 | |
| 555 | def minmax(x): |
| 556 | # type: (Any) -> Tuple[int, int] |
| 557 | m, M = reduce(lambda a, b: (min(a[0], b[0]), max(a[1], b[1])), |
| 558 | ((a, a) for a in x)) |
| 559 | if m == M: |
| 560 | m = 0 |
| 561 | if M == 0: |
| 562 | M = 1 |
| 563 | return m, M |
| 564 | |
| 565 | mins, maxs = minmax(x for x, _ in sl.values()) |
| 566 | mine, maxe = minmax(x for x, _ in el.values()) |
| 567 | mind, maxd = minmax(dl.values()) |
| 568 | |
| 569 | gr = 'digraph "afterglow" {\n\tedge [len=2.5];\n' |
| 570 |