mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
42c71845ed
commit
549fdc45af
2 changed files with 17 additions and 42 deletions
|
@ -3,9 +3,6 @@ package packets
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -13,40 +10,12 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
UPNPDestMac = net.HardwareAddr{0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb}
|
||||
UPNPDestIP = net.ParseIP("239.255.255.250")
|
||||
)
|
||||
|
||||
func NewUPNPProbe(from net.IP, from_hw net.HardwareAddr) (error, []byte) {
|
||||
eth := layers.Ethernet{
|
||||
SrcMAC: from_hw,
|
||||
DstMAC: UPNPDestMac,
|
||||
EthernetType: layers.EthernetTypeIPv4,
|
||||
}
|
||||
|
||||
ip4 := layers.IPv4{
|
||||
Protocol: layers.IPProtocolUDP,
|
||||
Version: 4,
|
||||
TTL: 64,
|
||||
SrcIP: from,
|
||||
DstIP: UPNPDestIP,
|
||||
}
|
||||
|
||||
udp := layers.UDP{
|
||||
SrcPort: layers.UDPPort(12345),
|
||||
DstPort: layers.UDPPort(UPNPPort),
|
||||
}
|
||||
|
||||
payload := []byte("M-SEARCH * HTTP/1.1\r\n" +
|
||||
UPNPDestMac = net.HardwareAddr{0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb}
|
||||
UPNPDestIP = net.ParseIP("239.255.255.250")
|
||||
UPNPDiscoveryPayload = []byte("M-SEARCH * HTTP/1.1\r\n" +
|
||||
fmt.Sprintf("Host: %s:%d\r\n", UPNPDestIP, UPNPPort) +
|
||||
"Man: ssdp:discover\r\n" +
|
||||
"ST: ssdp:all\r\n" +
|
||||
"MX: 2\r\n" +
|
||||
"\r\n")
|
||||
|
||||
if err := udp.SetNetworkLayerForChecksum(&ip4); err != nil {
|
||||
return err, nil
|
||||
}
|
||||
|
||||
return Serialize(ð, &ip4, &udp, gopacket.Payload(payload))
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue