-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (51 loc) · 1.12 KB
/
main.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
65
66
package main
import (
"flag"
"fmt"
"log"
"net"
"arp/client"
"arp/packet"
)
func getHdwAddrByIP(ip, itfc string) (string, error) {
c, err := client.New(itfc)
if err != nil {
return "", err
}
//TODO: steps for getting src ip and src hdwr addr need to be in `client.New` function
srcIP, err := client.GetSrcIPAddr(itfc)
if err != nil {
return "", err
}
srcHdwr, err := client.GetLocalMacAddr(itfc)
if err != nil {
return "", err
}
dstIP := net.ParseIP(ip).To4()
pkt, err := packet.MakePacket(packet.REQUEST, srcHdwr, srcIP.To4(), packet.Brodcast, dstIP)
if err != nil {
return "", err
}
addr, err := c.ResolveAddr(pkt, packet.Brodcast)
if err != nil {
return "", err
}
return addr.String(), nil
}
func main() {
itfc := flag.String("interface", "", "network interface")
internetProtocol := flag.String("ip", "", "destination ip")
flag.Parse()
if *itfc == "" || *internetProtocol == "" {
flag.PrintDefaults()
return
}
addr, err := getHdwAddrByIP(*internetProtocol, *itfc)
if err != nil {
log.Fatal(err)
}
fmt.Println(fmt.Sprintf(`
TARGET IP: %s
TARGET MAC: %s
`, *internetProtocol, addr))
}