|
@@ -30,17 +30,16 @@ var (
|
|
|
filter = flag.String("filter", "tcp", "PCAP filter expression")
|
|
|
promiscuous = flag.Bool("promiscuous", false, "Switch interface into promiscuous mode?")
|
|
|
natsURL = flag.String("nats-url", "nats://127.0.0.1:4222", "The URL of the NATS server")
|
|
|
- natsQueue = flag.String("nats-queue", "mami_requests", "The NATS queue name")
|
|
|
- sleepFor = flag.Duration("sleep", 0, "Sleep this long between sending data")
|
|
|
+ natsQueue = flag.String("nats-queue", "requests", "The NATS queue name")
|
|
|
+ sleepFor = flag.Duration("sleep", 0, "Sleep this long between sending data (only when replaying a file)")
|
|
|
requestsFile = flag.String("requests", "", "CSV file containing requests (IP and URL)")
|
|
|
useXForwardedAsSource = flag.Bool("use-x-forwarded", false, "Use the IP address in X-Forwarded-For as source")
|
|
|
doVersion = flag.Bool("version", false, "Show version information")
|
|
|
|
|
|
- dataChan chan data.Request
|
|
|
- natsEC *nats.EncodedConn
|
|
|
- count uint64
|
|
|
- timeout = -1 * time.Second
|
|
|
- ipPriv *ip.IP
|
|
|
+ natsEC *nats.EncodedConn
|
|
|
+ count uint64
|
|
|
+ timeout = -1 * time.Second
|
|
|
+ ipPriv *ip.IP
|
|
|
|
|
|
// Version contains the program Version, e.g. 1.0.1
|
|
|
Version string
|
|
@@ -90,11 +89,14 @@ func main() {
|
|
|
if *requestsFile != "" {
|
|
|
replayFile()
|
|
|
} else if *doLiveCapture {
|
|
|
+ fmt.Printf("live capture (%s, %s) to %s\n", *iface, *filter, *natsURL)
|
|
|
liveCapture()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func liveCapture() {
|
|
|
+ ipPriv = ip.NewIP()
|
|
|
+
|
|
|
// PCAP setup
|
|
|
//
|
|
|
handle, err := pcap.OpenLive(*iface, int32(*snapshotLen), *promiscuous, timeout)
|
|
@@ -225,7 +227,7 @@ func processPacket(packet gopacket.Packet) {
|
|
|
data.Source = data.XRealIP
|
|
|
}
|
|
|
|
|
|
- dataChan <- data
|
|
|
+ natsEC.Publish(*natsQueue, &data)
|
|
|
}
|
|
|
|
|
|
// replayFile takes a file containing a list of requests (SourceIP Url) and queues the requests
|