main.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "net"
  4. "sync"
  5. "github.com/inszva/tap0901"
  6. "time"
  7. "fmt"
  8. "encoding/hex"
  9. )
  10. func main() {
  11. //Create a new virtual network interface
  12. 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}))
  13. if err != nil {
  14. panic(err)
  15. }
  16. fmt.Println("Virtual Network Interface Created")
  17. time.Sleep(2 * time.Second)
  18. //create fucking DHCP IP
  19. err = tun.SetDHCPMasq(net.IP([]byte{162, 169, 228, 206}), net.IP([]byte{255, 255, 255, 0}),
  20. net.IP([]byte{0, 0, 0, 0}), net.IP([]byte{0, 0, 0, 0}))
  21. if err != nil {
  22. fmt.Println(err)
  23. }
  24. tun.Connect()
  25. time.Sleep(2 * time.Second)
  26. szName := tun.GetNetworkName(false)
  27. fmt.Println("Interface name: ", szName)
  28. tun.SetReadHandler(func (tun *tap0901.Tun, data []byte) {
  29. a := hex.EncodeToString(data)
  30. bs, _ := hex.DecodeString(a)
  31. fmt.Println(string(bs))
  32. })
  33. wp := sync.WaitGroup{}
  34. wp.Add(1)
  35. go func () {
  36. tun.Listen(1)
  37. wp.Done()
  38. } ()
  39. fmt.Println(tun.GetMTU(false))
  40. //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}))
  41. for {
  42. time.Sleep(3*time.Second)
  43. tun.Write([]byte("Hello World"))
  44. fmt.Println("Waiting")
  45. }
  46. time.Sleep(10*time.Second)
  47. tun.SignalStop()
  48. wp.Wait()
  49. }