Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example https://github.com/google/gopacket/blob/master/examples/synscan/main.go #1152

Open
CyberRoute opened this issue Jan 10, 2024 · 0 comments

Comments

@CyberRoute
Copy link

Hi,

recently I worked on a synscan and I started from the example there is in the repo. Although I find that pretty cool seems like sharing the handle when reading and writing packets to it causes troubles: scanning would become extremely slow and flaky e.g: on this https://gist.github.com/CyberRoute/5cd02e1ee10d1c4cef09e5cca1d6f57c

// scanner handles scanning a single IP address.
type scanner struct {
	// iface is the interface to send packets on.
	iface *net.Interface
	// destination, gateway (if applicable), and source IP addresses to use.
	dst, gw, src net.IP

	handle *pcap.Handle

	// opts and buf allow us to easily serialize packets in the send()
	// method.
	opts gopacket.SerializeOptions
	buf  gopacket.SerializeBuffer
}

After testing with handles decoupled for arp and tcp when reading packets everything goes pretty smooth and fast even without parallelism as on the example. e.g:

TCP:

ipFlow := gopacket.NewFlow(layers.EndpointIPv4, s.dst, s.src)

handle, err := pcap.OpenLive(s.iface.Name, 65535, true, pcap.BlockForever)
if err != nil {
	return err
}
defer handle.Close()

ARP:

arpDst := s.dst
if s.gw != nil {
	arpDst = s.gw
}
handle, err := pcap.OpenLive(s.iface.Name, 65536, true, pcap.BlockForever)
if err != nil {
	return nil, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant