-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
更新了 windows 下的 send arp 更新了 并发检测 更新了 多网卡检测
- Loading branch information
Showing
9 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
https://blog.cyeam.com/network/2015/03/16/fing | ||
|
||
探测局域网里面的设备 | ||
16 March 2015 | ||
IMG-THUMBNAIL | ||
|
||
用Golang实现Fing的功能。 | ||
之前用了一个牛逼的App,叫做Fing,它可以获取到本地局域网里面所有设备的IP、MAC地址和设备厂商。一直觉得很牛逼,今天好好想了想,发现也没那么多神秘。 | ||
|
||
穷举局域网里的IP | ||
局域网IP一般有192和10两种形式。一般来说,10开始的局域网高端一些,能容纳的设备比较多。 | ||
|
||
穷举所有IP,有一个方式是通过trancert命令,记录访问某个网站经过的路径,那么第一条路径就是访问路由器,得到路由器IP之后,按最后一部分进行穷举。 | ||
|
||
但是这个方法有点麻烦,简化一点的,就是获取当前设备在局域网里面的IP,以此IP进行穷举。通过Golang获取IP的方法可以参考[1]。获取当前设备IP的方式可以参考: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mostlygeek/arp" | ||
) | ||
|
||
func main() { | ||
for ip, _ := range arp.Table() { | ||
fmt.Printf("%s : %s\n", ip, arp.Search(ip)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// +build !windows | ||
|
||
package fing | ||
|
||
import ( | ||
"net" | ||
"time" | ||
|
||
"github.com/j-keck/arping" | ||
) | ||
|
||
func Mac(ip string) (net.HardwareAddr, time.Duration, error) { | ||
dstIP := net.ParseIP(ip) | ||
return arping.Ping(dstIP) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// +build windows | ||
|
||
package fing | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
"syscall" | ||
"time" | ||
"unsafe" | ||
) | ||
|
||
var SendARP = syscall.MustLoadDLL("iphlpapi.dll").MustFindProc("SendARP") | ||
|
||
func ip4ToUint32(ip net.IP) (uint32, error) { | ||
ip = ip.To4() | ||
if ip == nil { | ||
return 0, fmt.Errorf("ip address %v is not ip4", ip) | ||
} | ||
var ret uint32 | ||
for i := 4; i > 0; i-- { | ||
ret <<= 8 | ||
ret += uint32(ip[i-1]) | ||
} | ||
return ret, nil | ||
} | ||
|
||
func Mac(ip string) (net.HardwareAddr, time.Duration, error) { | ||
dstIP := net.ParseIP(ip) | ||
haddr, err := sendARP(dstIP) | ||
return haddr, time.Duration(0), err | ||
} | ||
|
||
func sendARP(ip net.IP) (net.HardwareAddr, error) { | ||
dst, err := ip4ToUint32(ip) | ||
if err != nil { | ||
return nil, err | ||
} | ||
mac := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff} | ||
n := uint32(len(mac)) | ||
ret, _, _ := SendARP.Call( | ||
uintptr(dst), | ||
0, | ||
uintptr(unsafe.Pointer(&mac[0])), | ||
uintptr(unsafe.Pointer(&n))) | ||
if ret != 0 { | ||
return nil, syscall.Errno(ret) | ||
} | ||
return mac, nil | ||
} | ||
|
||
// ExampleARP - | ||
func ExampleARP() { | ||
ip := "192.168.0.250" | ||
mac, _, err := Mac(ip) | ||
if err != nil { | ||
log.Fatalf("could not find MAC for %q: %v", ip, err) | ||
} | ||
fmt.Printf("MAC address for %v is %v\n", ip, mac) | ||
} |
Submodule go-ouitools
added at
ac8139
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/abserari/quicksilver/fing | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/dutchcoders/go-ouitools v0.0.0-20150909074929-ac8139d3326a | ||
github.com/j-keck/arping v1.0.1 | ||
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/dutchcoders/go-ouitools v0.0.0-20150909074929-ac8139d3326a h1:k0tlcLlo0xiIQ+PsvXHcMw5lmrWJ2dgtplMk5SnvAuw= | ||
github.com/dutchcoders/go-ouitools v0.0.0-20150909074929-ac8139d3326a/go.mod h1:iw2+sjeXZHqxa3T+ufyw4bBRZyfp5B4prg1YPMHV4V0= | ||
github.com/j-keck/arping v1.0.1 h1:XrO9juQieAQHE7DlwT7zFLUK2u3Oi/4Uz2B3ZTxvhxg= | ||
github.com/j-keck/arping v1.0.1/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw= | ||
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a h1:AfneHvfmYgUIcgdUrrDFklLdEzQAvG9AKRTe1x1mx/0= | ||
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a/go.mod h1:jZxafo9CAqaKFQE4zitrg5QNlA6CXUsjwXPlIppF3tk= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters