Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- "net"
- "strings"
- "github.com/google/gopacket/layers"
- )
- //Protocols bla-bla
- var Protocols = []layers.IPProtocol{
- layers.IPProtocolIPv6HopByHop,
- layers.IPProtocolICMPv4,
- layers.IPProtocolIGMP,
- layers.IPProtocolIPv4,
- layers.IPProtocolTCP,
- layers.IPProtocolUDP,
- layers.IPProtocolRUDP,
- layers.IPProtocolIPv6,
- layers.IPProtocolIPv6Routing,
- layers.IPProtocolIPv6Fragment,
- layers.IPProtocolGRE,
- layers.IPProtocolESP,
- layers.IPProtocolAH,
- layers.IPProtocolICMPv6,
- layers.IPProtocolNoNextHeader,
- layers.IPProtocolIPv6Destination,
- layers.IPProtocolOSPF,
- layers.IPProtocolIPIP,
- layers.IPProtocolEtherIP,
- layers.IPProtocolVRRP,
- layers.IPProtocolSCTP,
- layers.IPProtocolUDPLite,
- layers.IPProtocolMPLSInIP,
- }
- //EtherTypes bla-bla
- var EtherTypes = []layers.EthernetType{
- layers.EthernetTypeLLC,
- layers.EthernetTypeIPv4,
- layers.EthernetTypeARP,
- layers.EthernetTypeIPv6,
- layers.EthernetTypeCiscoDiscovery,
- layers.EthernetTypeNortelDiscovery,
- layers.EthernetTypeTransparentEthernetBridging,
- layers.EthernetTypeDot1Q,
- layers.EthernetTypePPP,
- layers.EthernetTypePPPoEDiscovery,
- layers.EthernetTypePPPoESession,
- layers.EthernetTypeMPLSUnicast,
- layers.EthernetTypeMPLSMulticast,
- layers.EthernetTypeEAPOL,
- layers.EthernetTypeQinQ,
- layers.EthernetTypeLinkLayerDiscovery,
- layers.EthernetTypeEthernetCTP,
- }
- //SetIPFlag function uses const values to set field of IP header
- func SetIPFlag(str string) layers.IPv4Flag {
- switch str {
- case "IPv4EvilBit":
- return layers.IPv4EvilBit
- case "IPv4DontFragment":
- return layers.IPv4DontFragment
- case "IPv4MoreFragments":
- return layers.IPv4MoreFragments
- }
- return 0
- }
- //SetIPProtocol function compares const values with input
- func SetIPProtocol(str string) layers.IPProtocol {
- for _, protocol := range Protocols {
- if protocol.String() == str {
- return protocol
- }
- }
- return 0
- }
- //AutoMAC function returns a mac addr of interface finding it by ip
- func AutoMAC(ip net.IP, interfArray []net.Interface) net.HardwareAddr {
- for _, inter := range interfArray {
- addrs, err := inter.Addrs()
- if err != nil {
- log.Fatal(err)
- }
- println()
- for _, addr := range addrs {
- str := addr.String()
- ippart := strings.Split(str, "/")
- if ip.String() == ippart[0] {
- return inter.HardwareAddr
- }
- }
- }
- return net.HardwareAddr{}
- }
- //SetEthType function finds a ethernet type in const enum
- func SetEthType(str string) layers.EthernetType {
- for _, i := range EtherTypes {
- if i.String() == str {
- return i
- }
- }
- return 0
- }
Add Comment
Please, Sign In to add comment