osociety / network_tools

Networking Tools library which can help you discover open ports, devices on subnet and many other things.
https://pub.dev/packages/network_tools
BSD 3-Clause "New" or "Revised" License
45 stars 13 forks source link

`PortScanner.discover` crash on Windows when scanning too many ports at once #22

Closed guyluz11 closed 2 years ago

guyluz11 commented 2 years ago

PortScanner.discover crash on Windows when scanning too many ports at once.

In my case the code got crash when running this

 PortScanner.discover(
    target,
    startPort: 1,
    endPort: 16350,

And didn't got crash when running this

PortScanner.discover(
    target,
    startPort: 20,
    endPort: 16350,

Here is the crash

Unhandled exception:
SocketException: Connection failed (OS Error: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.
, errno = 10055), address = 192.168.1.39, port = 16342
#0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:681:35)
#1      _NativeSocket.connect (dart:io-patch/socket_patch.dart:940:12)
#2      _RawSocket.connect (dart:io-patch/socket_patch.dart:1796:26)
#3      RawSocket.connect (dart:io-patch/socket_patch.dart:21:23)
#4      Socket._connect (dart:io-patch/socket_patch.dart:2019:22)
#5      Socket.connect (dart:io/socket.dart:770:21)
#6      PortScanner.connectToPort (package:network_tools/src/port_scanner.dart:156:37)
#7      PortScanner.customDiscover (package:network_tools/src/port_scanner.dart:87:13)
<asynchronous suspension>
git-elliot commented 2 years ago

High range should be avoided. Is there any need to scan from 1 to 16350 ?

guyluz11 commented 2 years ago

Not for me, but it will be useful for penetration testing applications.

git-elliot commented 2 years ago

I guess it's all happening when we are executing asynchronously, because it opens files and fills buffers in parallel. Although speed is high for scanning but at cost of file open and buffer limit.

git-elliot commented 2 years ago

User will have to scan in chunks, there is no other option.