瀏覽代碼

shit here

yeungalan 5 年之前
父節點
當前提交
160c63a69c
共有 3 個文件被更改,包括 87 次插入29 次删除
  1. 17 0
      .vscode/launch.json
  2. 二進制
      __debug_bin
  3. 70 29
      main.go

+ 17 - 0
.vscode/launch.json

@@ -0,0 +1,17 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Launch",
+            "type": "go",
+            "request": "launch",
+            "mode": "auto",
+            "program": "${fileDirname}",
+            "env": {},
+            "args": ["192.168.1.121:8181","10.0.1.1"]
+        }
+    ]
+}

二進制
__debug_bin


+ 70 - 29
main.go

@@ -1,58 +1,99 @@
 package main
 
 import (
+	"encoding/hex"
+	"fmt"
+	"github.com/inszva/tap0901"
 	"net"
+	"net/http"
+	//"net/url"
+	"os"
 	"sync"
-	"github.com/inszva/tap0901"
 	"time"
-	"fmt"
-	"encoding/hex"
 )
 
+//Create a new virtual network interface
+var tun, _ = tap0901.OpenTun(net.IP([]byte{0, 0, 0, 0}), net.IP([]byte{0, 0, 0, 0}), net.IP([]byte{0, 0, 0, 0}))
+
 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)
-    }
+	//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)
 
+	// type IP
+	IPAddress := net.ParseIP(os.Args[2])
+
 	//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}))
+	err := tun.SetDHCPMasq(IPAddress, net.IP([]byte{255, 0, 0, 0}),
+		net.IP([]byte{0, 0, 0, 0}), net.IP([]byte{0, 0, 0, 0}))
 	if err != nil {
-        fmt.Println(err)
-    }
-	
+		fmt.Println(err)
+	}
+
+	//create http server
+	http.HandleFunc("/rcv", rcv)
+	go func() {
+		http.ListenAndServe(":8181", nil)
+	}()
+
 	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))
+	fmt.Println("Dest IP:" + os.Args[1])
+
+	tun.SetReadHandler(func(tun *tap0901.Tun, data []byte) {
+		a := hex.EncodeToString(data)
+		//bs, _ := hex.DecodeString(a)
+		//fmt.Println(string(bs))
+		//fmt.Println(a)
+		resp, err := http.Get("http://" + os.Args[1] + "/rcv?packet=" + a)
+		if err != nil {
+			fmt.Println(err)
+		} else {
+			defer resp.Body.Close()
+		}
 	})
 	wp := sync.WaitGroup{}
 	wp.Add(1)
-	go func () {
+	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}))
+	//fmt.Println()
+	/*
+		for {
+			time.Sleep(3 * time.Second)
+			tun.Write([]byte("Hello World"))
+			fmt.Println("Waiting")
+		}
+		time.Sleep(10 * time.Second)
+		tun.SignalStop()
 
-	for {
-		time.Sleep(3*time.Second)
-		tun.Write([]byte("Hello World"))
-		fmt.Println("Waiting")
-	}
-	time.Sleep(10*time.Second)
-	tun.SignalStop()
+	*/
 	wp.Wait()
+}
 
+func rcv(w http.ResponseWriter, req *http.Request) {
+	fmt.Fprintf(w, "hello\n")
+	x, ok := req.URL.Query()["packet"]
+	if !ok || len(x[0]) < 1 {
+		fmt.Println("Url Param 'packet' is missing")
+		return
+	} else {
+		fmt.Println("Reciving data!!!")
+	}
+	data, err := hex.DecodeString(x[0])
+	if err != nil {
+		panic(err)
+	}
+	//fmt.Printf("% x", data)
+	tun.Write(data)
 }