ArticleslgStudy

computer science

Ngrep

Ngrep is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Ngrep rather than just read about it. In short: ngrep (network grep) is a network packet analyzer written by Jordan Ritter. It has a command-line interface, and relies upon the pcap library and the GNU regex library. ngrep supports Berkeley Packet Filter (BPF) logic to select network sources or destinations or protocols, and also allows matching patterns or regular expressions in the data payload of packets using GNU grep syntax, showing packet data in a human-fr…

Ngrep — main illustration
Ngrep — illustration

Key takeaways

  • Ngrep belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Ngrep to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Ngrep from memory before moving on to harder problems.

Reference excerpt

ngrep (network grep) is a network packet analyzer written by Jordan Ritter. It has a command-line interface, and relies upon the pcap library and the GNU regex library. ngrep supports Berkeley Packet Filter (BPF) logic to select network sources or destinations or protocols, and also allows matching patterns or regular expressions in the data payload of packets using GNU grep syntax, showing packet data in a human-friendly way. ngrep is an open source application, and the source code is available to download from the ngrep site on GitHub. It can be compiled and ported to multiple platforms, it works in many UNIX-like operating systems: Linux, Solaris, illumos, BSD, AIX, and also works on Microsoft Windows.

Functionality ngrep is similar to tcpdump, but it has the ability to look for a regular expression in the payload of the packet, and show the matching packets on a screen or console. It allows users to see all unencrypted traffic being passed over the network, by putting the network interface into promiscuous mode. ngrep with an appropriate BPF filter syntax, can be used to debug plain text protocols interactions like HTTP, SMTP, FTP, DNS, among others, or to search for a specific string or pattern, using a grep regular expression syntax. ngrep also can be used to capture traffic on the wire and store pcap dump files, or to read files generated by other sniffer applications like tcpdump or wireshark. ngrep has various options or command line arguments. The ngrep man page in UNIX-like operating systems show a list of available options.

Using ngrep In these examples, it is assumed that eth0 is the used network interface.

Capture network traffic incoming/outgoing to/from eth0 interface and show parameters following HTTP (TCP/80) GET or POST methods ngrep -l -q -d eth0 -i "^GET |^POST " tcp and port 80

Capture network traffic incoming/outgoing to/from eth0 interface and show the HTTP (TCP/80) User-Agent string ngrep -l -q -d eth0 -i "User-Agent: " tcp and port 80

Capture network traffic incoming/outgoing to/from eth0 interface and show the DNS (UDP/53) querys and responses ngrep -l -q -d eth0 -i "" udp and port 53

Security Capturing raw network traffic from an interface requires special privileges or superuser privileges on some platforms, especially on Unix-like systems. ngrep default behavior is to drop privileges in those platforms, running under a specific unprivileged user. Like tcpdump, it is also possible to use ngrep for the specific purpose of intercepting and displaying the communications of another user or computer, or an entire network. A privileged user running ngrep in a server or workstation connected to a device configured with port mirroring on a switch, router, or gateway, or connected to any other device used for network traffic capture on a LAN, MAN, or WAN, can watch all unencrypted information related to login ID's, passwords, or URLs and content of websites being viewed in that network.

Supported protocols IPv4 and IPv6, Internet Protocol version 4 and version 6 TCP, Transmission Control Protocol UDP, User Datagram Protocol ICMPv4 and ICMPv6, Internet Control Message Protocol version 4 and version 6 IGMP, Internet Group Management Protocol Ethernet, IEEE 802.3 PPP, Point to Point Protocol SLIP, Serial Line Internet Protocol FDDI, Fiber Data Distribution Protocol Token Ring, IEEE 802.5

See also

Comparison of packet analyzers snoop, a command line packet analyzer included with Solaris and illumos dsniff, a packet sniffer and set of traffic analysis tools netsniff-ng, a free Linux networking toolkit etherape, a network mapping tool that relies on sniffing traffic tcptrace, a tool for analyzing the logs produced by tcpdump Microsoft Network Monitor, a packet analyzer xplico, a network forensics analysis tool

References

External links Official site for ngrep

Illustrations

Ngrep illustration

Worked examples

Example 1 — a first encounter with Ngrep

Start with the simplest possible case. Write down what Ngrep claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Ngrep before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Ngrep ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Ngrep

In research
Ngrep appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Ngrep in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Ngrep is common in secondary-school and first-year university syllabi. It links to neighbouring topics Command-line software, Free network management software, Free software programmed in C, so understanding it makes those chapters shorter.
In everyday life
Look for Ngrep outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Ngrep in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Ngrep means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Ngrep out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Ngrep in simple terms?

ngrep (network grep) is a network packet analyzer written by Jordan Ritter. It has a command-line interface, and relies upon the pcap library and the GNU regex library. ngrep supports Berkeley Packet Filter (BPF) logic to select network sources or destinations or protocols, and also allows matching…

Why does Ngrep matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Ngrep?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Ngrep.

Tags

  • Command-line software
  • Free network management software
  • Free software programmed in C
  • MacOS security software
  • Network analyzers
  • Software using the BSD license
  • Unix network-related software
  • Windows security software

Keep exploring