-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrySysc.go
64 lines (56 loc) · 1.11 KB
/
trySysc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"net"
"fmt"
"syscall"
"time"
"bytes"
)
func main() {
fmt.Println(net.InterfaceAddrs())
l, _ := net.Interfaces()
for _, v := range l {
fmt.Println(v)
}
fd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_PACKET, 0x0300)
if err != nil {
fmt.Println("socket", err)
}
defer syscall.Close(fd)
if err = syscall.BindToDevice(fd, "eth1"); err != nil {
fmt.Println("bind", err)
panic(err)
}
for {
b := make([]byte, 100)
_, _, _ = syscall.Recvfrom(fd, b, 0)
if ! IsIcmpPac(b) {
continue
}
//fmt.Printf("%5x\n", b[12:14])
//continue
for k, v := range b {
if k % 4 == 2 {
fmt.Println()
}
fmt.Printf("|%4d: %5d:0x%-5x|", k, v, v)
}
fmt.Println("\na packet-----------")
}
time.Sleep(1 * time.Second)
fmt.Println(fd)
}
func IsIpPac(pack []byte) bool {
return bytes.Equal(pack[12:14], []byte{8, 0})
}
func IsArpPac(pack []byte) bool {
return bytes.Equal(pack[12:14], []byte{8, 6})
}
func IsIcmpPac(pack []byte) bool {
//fmt.Println("the 23", pack[23])
if bytes.Equal(pack[12:14], []byte{8, 0}) && pack[23] == 1 {
return true
} else {
return false
}
}