arpresolve

package
v0.0.0-...-5c98b36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2022 License: MulanPSL-2.0 Imports: 8 Imported by: 0

README

arpresolve

使用 ARP 请求获取局域网内某个主机的MAC地址

Example:

package main

import (
	"flag"
	"fmt"
	"log"
	"net"
	"os"

	"gitee.com/sillyman/simpleUtil/network/arpresolve"
)

var (
	localIP  = flag.String("lip", "", "IP address of local interface")
	remoteIP = flag.String("rip", "", "IP address of host in LAN")
)

func main() {
	flag.Parse()
	if *localIP == "" || *remoteIP == "" {
		flag.PrintDefaults()
		os.Exit(1)
	}

	remoteMAC, err := arpresolve.Resolve(net.ParseIP(*localIP), net.ParseIP(*remoteIP), 3)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("%s => %s", *remoteIP, remoteMAC)
}
Output:
192.168.228.1 => 4c1f-cc11-dac5

Documentation

Overview

Package arpresolve 使用 ARP 请求获取局域网内某个主机的MAC地址

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolve

func Resolve(localIP, remoteIP net.IP, retries int) (mac macaddr.MAC, err error)

Resolve 发送 ARP 请求获取目标IP地址的MAC地址(可能需要管理员身份才能访问raw socket) 依赖 pcap 库

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL