Ngrep

From 탱이의 잡동사니
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Overview

리눅스 명령어 ngrep 사용 정리.

Basic

ngrep 은 network grep 의 줄임말이며, grep 과 비슷한 개념이지만 네트워크 패킷의 내용을 검색한다는 것이 다르다.

Options

Synopsis

$ ngrep <-hNXViwqpevxlDtTRM> <-IO pcap_dump > < -n num > < -d dev > < -A num > < -s snaplen > \ 
   < -S limitlen > < -W normal|byline|single|none > < -c cols > < -P char > < -F file > < match expression > < bpf filter >

-q

Quiet 옵션. 패킷 헤더와 페이로드를 제외한 다른 내용은 표시하지 않는다.

-v

Invert. 매칭되는 패킷은 제외하고 표시한다.

-t/-T

Timestamp 를 표시한다. -t 옵션은 패킷이 도착한 시간을 표시하고, -T 옵션은 패킷간의 간격을 시간으로 표시한다.

-W

  • normal:
normal is the default mode and is only included for completeness. This option is incompatible with -x.
  • byline:
The byline mode honors embedded linefeeds, wrapping text only when a linefeed is encountered (useful for observing HTTP transactions, for instance).
  • single:
The single mode is conceptually the same as none, except that everything including IP and source/destination header information is all on one line.
  • none:
The none mode doesn't wrap under any circumstance (entire payload is displayed on one line).

host

source/destination 모두에 입력한 주소값을 매칭시킨다.

dst host : destination 에만 주소값을 매칭시킨다. src host : source 에만 주소값을 매칭시킨다.

port

입력한 포트주소를 감시한다.

$ ngrep -qt port 9091
interface: eth0.843 (127.0.0.1/255.255.255.0)
filter: (ip or ip6) and ( port 9091 )

Examples

pchero@mywork:~$ sudo ngrep -qt host 10.1.27.62
interface: eth0 (10.1.27.0/255.255.255.0)
filter: (ip or ip6) and ( host 10.1.27.62 )

T 2015/08/28 13:05:48.617855 173.252.102.16:443 -> 10.1.27.62:57349 [AP]
  ....CL.Z.F.D.(......\E.Ys.%..Nj.O.?I.-.l..wQi..d= '.........@d.0.p..!l..

SIP packet

$ ngrep -W byline "SIP" -qt src host 127.0.0.1 or dst host 192.168.200.10

See also