|
|
@@ -1,6 +1,7 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "bufio"
|
|
|
"encoding/hex"
|
|
|
"fmt"
|
|
|
"github.com/songgao/packets/ethernet"
|
|
|
@@ -10,7 +11,7 @@ import (
|
|
|
"os"
|
|
|
"os/exec"
|
|
|
"strings"
|
|
|
- "bufio"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
@@ -21,9 +22,20 @@ var ifce, _ = water.New(water.Config{
|
|
|
DeviceType: water.TAP,
|
|
|
})
|
|
|
|
|
|
+var RCV_B = 0
|
|
|
+var TXT_B = 0
|
|
|
+
|
|
|
func main() {
|
|
|
+ //for stat only
|
|
|
+ go func() {
|
|
|
+ for {
|
|
|
+ log.Println("Total reciving: ", RCV_B, ", Total transmitting: ", TXT_B)
|
|
|
+ time.Sleep(5 * time.Second)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
//create http server
|
|
|
- go func(){
|
|
|
+ go func() {
|
|
|
fmt.Println("Launching server...")
|
|
|
// listen on all interfaces
|
|
|
ln, _ := net.Listen("tcp", ":8081")
|
|
|
@@ -34,8 +46,9 @@ func main() {
|
|
|
// will listen for message to process ending in newline (\n)
|
|
|
message, _ := bufio.NewReader(conn).ReadString('\n')
|
|
|
// output message received
|
|
|
- fmt.Print("RECV<<", string(message))
|
|
|
- data, err := hex.DecodeString( strings.ReplaceAll("\n","",string(message)))
|
|
|
+ //fmt.Print("RECV<<", string(message))
|
|
|
+ RCV_B += len(string(message))
|
|
|
+ data, err := hex.DecodeString(strings.ReplaceAll("\n", "", string(message)))
|
|
|
if err != nil {
|
|
|
//log.Println(err)
|
|
|
}
|
|
|
@@ -46,7 +59,7 @@ func main() {
|
|
|
|
|
|
//declare server
|
|
|
// connect to server
|
|
|
- conns, _ := net.Dial("tcp",os.Args[1]+":8081")
|
|
|
+ conns, _ := net.Dial("tcp", os.Args[1]+":8081")
|
|
|
|
|
|
var frame ethernet.Frame
|
|
|
setupIfce(net.IPNet{IP: self, Mask: mask}, ifce.Name())
|
|
|
@@ -58,15 +71,16 @@ func main() {
|
|
|
log.Fatal(err)
|
|
|
}
|
|
|
frame = frame[:n]
|
|
|
- log.Println("TRSV>>", hex.EncodeToString(frame))
|
|
|
-/*
|
|
|
- log.Printf("Dst: %s\n", frame.Destination())
|
|
|
- log.Printf("Src: %s\n", frame.Source())
|
|
|
- log.Printf("Ethertype: % x\n", frame.Ethertype())
|
|
|
- log.Printf("Payload: % x\n", frame.Payload())
|
|
|
- log.Printf("HEX: % x\n", frame)
|
|
|
-*/
|
|
|
- fmt.Fprintf(conns, hex.EncodeToString(frame) + "\n")
|
|
|
+ //log.Println("TRSV>>", hex.EncodeToString(frame))
|
|
|
+ TXT_B += len(hex.EncodeToString(frame))
|
|
|
+ /*
|
|
|
+ log.Printf("Dst: %s\n", frame.Destination())
|
|
|
+ log.Printf("Src: %s\n", frame.Source())
|
|
|
+ log.Printf("Ethertype: % x\n", frame.Ethertype())
|
|
|
+ log.Printf("Payload: % x\n", frame.Payload())
|
|
|
+ log.Printf("HEX: % x\n", frame)
|
|
|
+ */
|
|
|
+ fmt.Fprintf(conns, hex.EncodeToString(frame)+"\n")
|
|
|
/*
|
|
|
a := hex.EncodeToString(frame)
|
|
|
|
|
|
@@ -80,7 +94,6 @@ func main() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
func setupIfce(ipNet net.IPNet, dev string) {
|
|
|
sargs := fmt.Sprintf("interface ip set address name=REPLACE_ME source=static addr=REPLACE_ME mask=REPLACE_ME gateway=none")
|
|
|
args := strings.Split(sargs, " ")
|