package main import ( "net" "sync" "github.com/inszva/tap0901" "time" "fmt" "encoding/hex" ) func main() { //Create a new virtual network interface tun, err := tap0901.OpenTun(net.IP([]byte{0, 0, 0, 0}), net.IP([]byte{0,0,0,0}), net.IP([]byte{0,0,0,0})) if err != nil { panic(err) } fmt.Println("Virtual Network Interface Created") time.Sleep(2 * time.Second) //create fucking DHCP IP err = tun.SetDHCPMasq(net.IP([]byte{162, 169, 228, 206}), net.IP([]byte{255, 255, 255, 0}), net.IP([]byte{0, 0, 0, 0}), net.IP([]byte{0, 0, 0, 0})) if err != nil { fmt.Println(err) } tun.Connect() time.Sleep(2 * time.Second) szName := tun.GetNetworkName(false) fmt.Println("Interface name: ", szName) tun.SetReadHandler(func (tun *tap0901.Tun, data []byte) { a := hex.EncodeToString(data) bs, _ := hex.DecodeString(a) fmt.Println(string(bs)) }) wp := sync.WaitGroup{} wp.Add(1) go func () { tun.Listen(1) wp.Done() } () fmt.Println(tun.GetMTU(false)) //fmt.Println(tun.Write([]byte{0x45, 0x00, 0x00, 0x23, 0x12, 0xa5, 0x00, 0x40, 0x11, 0xf3, 0x28, 0x7b, 0x02, 0x03, 0x04, 0x7b, 0x7b, 0x7b, 0x7b, 0x3d, 0x1d, 0x63, 0x71, 0x00, 0x0f, 0x59, 0x17, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67})) for { time.Sleep(3*time.Second) tun.Write([]byte("Hello World")) fmt.Println("Waiting") } time.Sleep(10*time.Second) tun.SignalStop() wp.Wait() }