Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 43 lines (35 sloc) 1.25 KB
#!/usr/bin/env node
/*global process require exports */
var sys = require("sys"),
pcap = require("pcap"), pcap_session;
if (process.argv.length > 4) {
sys.error("usage: simple_capture interface filter");
sys.error("Examples: ");
sys.error(' simple_capture "" "tcp port 80"');
sys.error(' simple_capture eth1 ""');
sys.error(' simple_capture lo0 "ip proto \\tcp and tcp port 80"');
process.exit(1);
}
pcap_session = pcap.createSession(process.argv[2], process.argv[3]);
// libpcap's internal version numnber
sys.puts(pcap.lib_version);
// Print all devices, currently listening device prefixed with an asterisk
pcap_session.findalldevs().forEach(function (dev) {
if (pcap_session.device_name === dev.name) {
sys.print("* ");
}
sys.print(dev.name + " ");
if (dev.addresses.length > 0) {
dev.addresses.forEach(function (address) {
sys.print(address.addr + "/" + address.netmask);
});
sys.print("\n");
} else {
sys.print("no address\n");
}
});
// Listen for packets, decode them, and feed the simple printer. No tricks.
pcap_session.on('packet', function (raw_packet) {
var packet = pcap.decode.packet(raw_packet);
sys.puts(pcap.print.packet(packet));
});
Something went wrong with that request. Please try again.