Skip to content

Commit

Permalink
Merge pull request #84 from jpillora/patch-1
Browse files Browse the repository at this point in the history
Create inject.js example
  • Loading branch information
ujjwalt committed Dec 29, 2013
2 parents f3cd761 + 85901cc commit beb653a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/inject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var iface = process.argv[2];

if(!iface) {
console.log("usage: node inject <interface>");
process.exit(1);
}

//first, lets watch for all ARP frames on eth0:
// `tcpdump -i <interface> arp`

//then lets send our custom frame
// `node inject.js <interface>`

var pcap = require("pcap"),
session = pcap.createSession(iface, "");

var arpRequest = new Buffer([
0xff,0xff,0xff,0xff,0xff,0xff, //dst
0xf6,0xb5,0xc6,0x9b,0x43,0x35, //src
0x08,0x06, //type - arp
0x00,0x01, //htype - 0x0001 (ethernet)
0x08,0x00, //ptype - 0x8000 (ip)
0x06, //hlen
0x04, //plen
0x00,0x01, //op - (reply)
0xf6,0xb5,0xc6,0x9b,0x43,0x35, //hsrc
0x0a,0x00,0x00,0x01, //psrc 10.0.0.1
0x00,0x00,0x00,0x00,0x00,0x00, //hdst
0x0a,0x00,0x00,0x02 //pdst 10.0.0.2
]);

session.inject(arpRequest);

console.log("sent ARP request");

process.nextTick(process.exit);

0 comments on commit beb653a

Please sign in to comment.