network_tools
Networking Tools library which can help you discover open ports, devices on subnet and many other things.
Networking Tools library which can help you discover open ports, devices on subnet and many other things.
English project snapshot. Visit GitHub for the latest content.
Network Tools Supported
Host Scanner
Port Scanner
Partly Work:
Please check network_tools_flutter package for extensive support to features on different platforms.
import 'package:network_tools/network_tools.dart';
Future<void> main() async {
await configureNetworkTools('build', enableDebugging: true);
runApp(const MyApp());
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// It's necessary to pass correct path to be able to use this library.
final appDocDirectory = await getApplicationDocumentsDirectory();
await configureNetworkTools(appDocDirectory.path, enableDebugging: true);
runApp(const MyApp());
}
String address = '192.168.1.12';
// or You can also get address using network_info_plus package
// final String? address = await (NetworkInfo().getWifiIP());
final String subnet = address.substring(0, address.lastIndexOf('.'));
final stream = HostScannerService.instance.getAllPingableDevices(subnet, firstHostId: 1, lastHostId: 50,
progressCallback: (progress) {
print('Progress for host discovery : $progress');
});
stream.listen((host) {
//Same host can be emitted multiple times
//Use Set<ActiveHost> instead of List<ActiveHost>
print('Found device: $host');
}, onDone: () {
print('Scan completed');
}); // Don't forget to cancel the stream when not in use.
//1. Range
String target = '192.168.1.1';
PortScannerService.instance.scanPortsForSingleDevice(target, startPort: 1, endPort: 1024,
progressCallback: (progress) {
print('Progress for port discovery : $progress');
}).listen((ActiveHost event) {
if (event.openPorts.isNotEmpty) {
print('Found open ports : ${event.openPorts}');
}
}, onDone: () {
print('Scan completed');
});
//2. Single
bool isOpen = (await PortScanner.isOpen(target, 80)) == null;
//3. Custom
PortScanner.customDiscover(target, portList: const [22, 80, 139]);
for (final ActiveHost activeHost in await MdnsScannerService.instance.searchMdnsDevices()) {
final MdnsInfo? mdnsInfo = await activeHost.mdnsInfo;
print('''
Address: ${activeHost.address}
Port: ${mdnsInfo!.mdnsPort}
ServiceType: ${mdnsInfo.mdnsServiceType}
MdnsName: ${mdnsInfo.getOnlyTheStartOfMdnsName()}
''');
}
dart example/host_scan.dartdart example/port_scan.dartdart example/mdns_scan.dartVernet is the open source app built on top of this library. You can check out the code and implementation for more detailed use case of this package.
Support this project by becoming stargazer of this project.
Buy me a coffee.
| Librepay |
|---|
Support me on Ko-Fi
Inspired from ping_discover_network
Dependency list 21 items
^8.0.0>=9.0.1 <11.0.0^2.34.0^9.2.1^1.6.0>=2.5.1 <4.0.0^4.12.0^1.3.0^0.3.3^1.9.1^1.3.3>=2.8.0 <4.0.0>=0.5.0 <2.0.0^2.3.1^2.4.13^2.34.0>=2.8.1 <4.0.0^6.10.0^2.3.0^1.0.3^1.25.8Start with your use case, compare repository activity, and check the original project before adopting it.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗