Comments (8)
Can you provide the exact code you're trying and any errors you get?
from cap.
I used the exact first example code on the readme and just changed the ip to 127.0.0.1
then got the error device must be string
. If I change the ip to my network IP it works well.
When I try to console log the deviceList()
I only get 1 and that is my AMD PCNET Ethernet Adapter
using the network IP and that is it.
Further more I tried
device = Cap.findDevice('127.0.0.1')
console.log(device)
Is undefined. (still using the example)
from cap.
After some more research it seems that you can't listen on loopback addresses on Windows with WinPCap as those packets typically do not get sent to any network drivers and are managed internally by Windows instead. However *nix handles loopback a little differently so you can capture that kind of traffic on those platforms.
However according to this mailing list post, you may be able to capture (higher-level) traffic using some other low level Windows APIs.
from cap.
I did try some things from microsoft. This wiki on wireshark is very helpful. But it's still no good for me as I still cant get the loopback adapter.
What could rawcap be using, they can capture loopback adapter packets.
from cap.
It's hard to say what exactly rawcap is using because it doesn't seem to be open source, but it's probably using one of the methods mentioned in the mailing list post I linked to.
Someone wrote a .NET library that uses the Windows Packet Filtering API underneath, so if you're comfortable with .NET you might give that a try.
from cap.
@mscdex If I run the first example from the readme on osx and change ip to 127.0.0.1
I get the same issue as mentioned here.
$ sudo node foo.js
/private/tmp/foo.js:11
var linkType = c.open(device, filter, bufSize, buffer);
^
TypeError: device must be a string
at TypeError (native)
at Object.<anonymous> (/private/tmp/foo.js:11:18)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3
The code is the same as the one in the readme, just added here for clarity:
var Cap = require('cap').Cap,
decoders = require('cap').decoders,
PROTOCOL = decoders.PROTOCOL;
var c = new Cap(),
device = Cap.findDevice('127.0.0.1'),
filter = 'tcp and dst port 80',
bufSize = 10 * 1024 * 1024,
buffer = new Buffer(65535);
var linkType = c.open(device, filter, bufSize, buffer);
c.setMinBytes && c.setMinBytes(0);
c.on('packet', function(nbytes, trunc) {
console.log('packet: length ' + nbytes + ' bytes, truncated? '
+ (trunc ? 'yes' : 'no'));
// raw packet data === buffer.slice(0, nbytes)
if (linkType === 'ETHERNET') {
var ret = decoders.Ethernet(buffer);
if (ret.info.type === PROTOCOL.ETHERNET.IPV4) {
console.log('Decoding IPv4 ...');
ret = decoders.IPV4(buffer, ret.offset);
console.log('from: ' + ret.info.srcaddr + ' to ' + ret.info.dstaddr);
if (ret.info.protocol === PROTOCOL.IP.TCP) {
var datalen = ret.info.totallen - ret.hdrlen;
console.log('Decoding TCP ...');
ret = decoders.TCP(buffer, ret.offset);
console.log(' from port: ' + ret.info.srcport + ' to port: ' + ret.info.dstport);
datalen -= ret.hdrlen;
console.log(buffer.toString('binary', ret.offset, ret.offset + datalen));
} else if (ret.info.protocol === PROTOCOL.IP.UDP) {
console.log('Decoding UDP ...');
ret = decoders.UDP(buffer, ret.offset);
console.log(' from port: ' + ret.info.srcport + ' to port: ' + ret.info.dstport);
console.log(buffer.toString('binary', ret.offset, ret.offset + ret.info.length));
} else
console.log('Unsupported IPv4 protocol: ' + PROTOCOL.IP[ret.info.protocol]);
} else
console.log('Unsupported Ethertype: ' + PROTOCOL.ETHERNET[ret.info.type]);
}
});
from cap.
@freeall This should be fixed in 544c65c but you will need to also make sure you run with sudo
to make sure you can get available network interface information (and start actual packet capturing). Although I know on linux you can avoid sudo
by using setcap
, but it needs to be done on the node executable IIRC which may not be desirable. On OS X I think you can just change the permissions on the /dev/bpf*
devices (but this is only temporary)?
from cap.
@mscdex Thanks a lot for fixing really fast! Now we can continue working on this module we're doing where we want to read all streams. Will probably come out later tonight if it works well.
from cap.
Related Issues (20)
- 0 bytes packets capture only HOT 11
- Issue installing cap on Windows 10 HOT 6
- TypeError: Cannot read property 'prototype' of undefined HOT 3
- 'cap.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 83. This version of Node.js requires NODE_MODULE_VERSION 89. HOT 1
- Create a packet
- This module was compiled agianst a different Node.js issue.
- `Cap.deviceList()` Permissions error HOT 2
- "Segmentation fault (core dumped)" while using cap to send many packet (number of packets < 60) HOT 1
- how to check if npcap is installed on the machine HOT 1
- Return read packets immediately on Windows 10 HOT 2
- "The specified module could not be found" HOT 5
- Does not compile under the newest node-gyp / electron-gyp HOT 2
- NODE_MODULE_VERSION 72. This version of Node.js requires NODE_MODULE_VERSION 73. Please try re-compiling or re-installing HOT 13
- .
- Does not find Pcap Library HOT 1
- Loop starvation HOT 2
- Resend packet captured from Wireshark HOT 5
- Can I send a WebSocket package without worrying about ACK number or Seq number? HOT 1
- Capture TCP segment of Reassembled PDU?
- How do I regenerate the seq number to replay captured traffic?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cap.