Open zboya opened 6 years ago
@lixin9311
@lixin9311
package main
import (
"log"
"github.com/songgao/packets/ethernet"
"github.com/songgao/water"
)
func main() {
ifce, err := water.New(water.Config{
DeviceType: water.TAP,
PlatformSpecificParams: water.PlatformSpecificParams{
ComponentID: "tap0901",
Network: "10.8.0.6/30",
},
})
if err != nil {
log.Fatal(err)
}
var frame ethernet.Frame
for {
frame.Resize(1500)
n, err := ifce.Read([]byte(frame))
if err != nil {
log.Fatal(err)
}
frame = frame[:n]
log.Printf("Dst: %s\n", frame.Destination())
log.Printf("Src: %s\n", frame.Source())
log.Printf("Ethertype: % x\n", frame.Ethertype())
log.Printf("Payload %s\n", frame.Payload())
}
}
go run main.go
netsh interface ip set address name="Ehternet 2" source=static addr=10.8.0.6 mask=255.255.255.252 gateway=none
ping 10.8.0.6
no printing. Orz
you should run the program as admin on UAC enabled Windows
And if you ping the address of the virtual nic on the local machine, the NT kernel will intercept and reply the ping, you can try to ping the gateway via the tun device
how do i send all data to Virtual Ethernet Adapter? when I send the command “route add 0.0.0.0 mask 0.0.0.0 10.8.0.6" in cmd tools and then visit the website .I can catch data from wireshark ,but can't read data from main program
@JavinYang when I using TAP device, it can read data from main program. using TUN device don't work.
set the address of the adapter to 192.168.1.10/24 and the gateway 192.168.1.1/24. you ping the gateway, then you can read the data.
@lixin9311 I had set the address of the adapter to 192.168.1.10/24 and the gateway 192.168.1.1/24. but using the TUN device still can't read data. using TAP device can read data.
it's working on my pc, I'll look into this later
I run this program in windows 10 in parallels desktop. maybe the vm has some different.
I run this program in real windows 10, and found the Nic can't set IP address to 192.168.1.10, it set the IP address to 169.254.x.x, this IP address is assigned by system, not my program.
there's some issue with netsh, you can try to set the ip by right clicking on the adapter icon.
@lixin9311 how did you set windows gateway?what cmd you used?
after run this program, I ping 192.168.1.10, but program print nothing. Please help!