probe/ping/ping_test.go

67 lines
1.2 KiB
Go
Raw Normal View History

2018-08-12 10:24:23 +00:00
package ping
import (
"fmt"
"log"
"testing"
"github.com/google/gopacket"
"github.com/google/gopacket/pcap"
)
func TestPing(t *testing.T) {
ip := "192.168.1.229"
port := 6379
portType := "TCP"
key := "REDIS"
tls := false
ch := make(chan Res)
Ping(ch, ip, port, tls, portType, key)
for res := range ch {
if res.Error != nil {
t.Error(res.Error)
} else {
t.Log(res.Matcher.Name())
t.Log(res.Matcher.Meta())
}
}
}
func TestPcap(t *testing.T) {
devices, err := pcap.FindAllDevs()
if err != nil {
log.Fatal(err)
}
// Print device information
fmt.Println("Devices found:")
for _, d := range devices {
fmt.Println("\nName: ", d.Name)
fmt.Println("Description: ", d.Description)
fmt.Println("Devices addresses: ", d.Description)
for _, address := range d.Addresses {
fmt.Println("- IP address: ", address.IP)
fmt.Println("- Subnet mask: ", address.Netmask)
}
}
h, err := pcap.OpenLive("{1924FA2B-6927-4BA5-AF43-876C3F8853CE}", 1600, true, pcap.BlockForever)
if err != nil {
t.Error(err)
}
if err = h.SetBPFFilter("tcp"); nil != err {
h.Close()
t.Error(err)
}
packetSource := gopacket.NewPacketSource(h, h.LinkType())
for packet := range packetSource.Packets() {
fmt.Printf("%s", packet.Dump())
}
}