network-monitor
network-monitor copied to clipboard
Dependencies update
Network-manager is in trouble :(
I really appreciate this tool but him was out-of-date with some dependencies, and unfortunaly was impossible run the network-manager.
But we can fix it! :)
So, I wasted a entire day to resolve that problem and now I'm happy to say that is working nicely. Yeah!
Basically, this is what I did:
- I updated one nomenclature of a function
- I adjusted the way to validate when the packet is TCP
- I installed http-trace to decode HTTP traffic
- I override HTTPSession event to listen http request
- I put some commentaries on the code to more explanations
Great work @LucasLannes!
However, I feel this is kind of a hacky solution. I will try to refine it a little further before merging it in the coming time. Thanks!
Explanation about "I adjusted the way to validate when the packet is TCP"
This line of code:
if(packet.link.ip.protocol_name === 'TCP')
Turned:
if(packet.payload.payload.payload instanceof TCP)
Because the node_pcap modified the packet object structure and I follow the same method used by them here.
Explanation about "I override HTTPSession event to listen http request"
Originally, you use this to listen HTTP Requests:
tcp_tracker.on('http request', function(session, http) { } )
But, now, TCPTracker only have those events: session, syn retry, reset, start, retransmit, data send, data recv and end.
tcp_tracker.on('session', function (tcp_session) { } )
TCPTracker on session receives an object that don't contains the HTTP data decoded, and to get this information we use the HTTPSession of the http-trace:
var http_session = new HTTPSession(tcp_session)
Yes, this is a hack because if we require whole http-trace...
var http_trace = require('http_trace')
All the HTTP traffic will be catched automatically by http-trace and showed using console.log, this is the default behaviour.
An example of output:
00:21:21.521 192.168.1.51:50757 -> 192.168.1.180:8080 #1 HTTP 1.1 request: GET /
00:21:21.521 192.168.1.180:8080 -> 192.168.1.51:50757 #1 HTTP 1.0 response: 200 OK
00:21:21.521 192.168.1.180:8080 -> 192.168.1.51:50757 #1 HTTP 1.0 response body: 1278B
Finally, we override the event listener of the HTTPSession to modify the default behaviour:
http_session.on("http request", function (session) { } ) // session have the HTTP decoded
And show the display in UI like the original network-manager.
@DhavalKapil I hope this explanations were good for you, because is my first "technical article" :)
Your explanation makes perfect sense. I am sure the solution will be along the same lines. I just don't like depending upon files in 'node_modules'. I want a more general solution.
@LucasLannes are you still receiving output from http_trace ?