File: stenoread

package info (click to toggle)
stenographer 1.0.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,192 kB
  • sloc: cpp: 2,087; sh: 830; yacc: 257; makefile: 102
file content (75 lines) | stat: -rwxr-xr-x 2,426 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [ "$#" -lt 1 ]; then
  cat >&2 <<EOF
$0 provides a simple method for reading logs out of stenographer.
Its first argument is the query to send to stenographer, all other arguments
are passed to TCPDump.

Examples:
 # Print all packets for source IP 1.1.1.1 without DNS resolution (-n).
 $0 'host 1.1.1.1' -n src host 1.1.1.1
 # Print all PSH packets between 1.1.1.1 and 2.2.2.2:
 $0 'host 1.1.1.1 and host 2.2.2.2' -n 'tcp[tcpflags] & tcp-push != 0'
 # Write all packets between 1.1.1.1 and 2.2.2.2 to disk.
'host 1.1.1.1 and host 2.2.2.2' -w /tmp/out.pcap

See README.md for more details on the Stenographer query language.

Set the STENOGRAPHER_CONFIG environmental variable to point to your stenographer
config if it's in a nonstandard place (defaults to /etc/stenographer/config).

$0 arguments are given before the filter.  These include:
  --limit-bytes X    :  Stop output once we've exceeded X bytes
  --limit-packets X  :  Stop output once we've exceeded X packets

For example:
  # Print first 6 packets or 2K bytes, whichever comes first,
  # from source IP 1.1.1.1
  $0 --limit-packets 6 --limit-bytes 2048 'host 1.1.1.1'
EOF
  exit 1
fi

HEADERS=""
while true; do
  case "$1" in
    --limit-packets)
      HEADERS="$HEADERS --header Steno-Limit-Packets:$2"
      shift 2
      ;;
    --limit-bytes)
      HEADERS="$HEADERS --header Steno-Limit-Bytes:$2"
      shift 2
      ;;
    *)
      STENOQUERY="$1"
      shift
      break
      ;;
  esac
done

TCPDUMP=$(PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin which tcpdump)
STENOCURL=$(PATH=$(dirname "$0"):$PATH which stenocurl)

echo "Running stenographer query '$STENOQUERY', piping to 'tcpdump $@'" >&2
"$STENOCURL" /query \
    -d "$STENOQUERY" \
    --silent \
    --max-time 890 \
    --show-error $HEADERS |
    "$TCPDUMP" -r /dev/stdin -s 0 "$@"