Skip to content

ikascom/react-native-lan-port-scanner

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

react-native-lan-port-scanner

A simple port scanner for react native.

npm version npm MIT
Platform - Android Platform - iOS

Installation

This package requires react-native-tcp depedency, please install it first.

yarn add react-native-lan-port-scanner

or

npm install react-native-lan-port-scanner

Don't forget to run pod install after that!

Usage

Scan all network hosts with specific ports

import LanPortScanner, { LSConfig }  from 'react-native-lan-port-scanner';

//Returns `LSNetworkInfo`
 const networkInfo = await LanPortScanner.getNetworkInfo()

 let config: LSConfig = {
   networkInfo: networkInfo,
   ports: [80, 8085], //Specify port here
   timeout: 1000, //Timeout for each thread in ms
   threads: 150 //Number of threads
 }
 LanPortScanner.startScan(config, (totalHosts: number, hostScanned: number) => {
   console.log(hostScanned / totalHosts) //Show progress
 }, (result) => {
   console.log(result) //This will call after new ip/port found.
 }, (results) => {
   console.log(results) // This will call after scan end.
 })

To scan specifc host with port

  //Returns `LSSingleScanResult`
  let result = await LanPortScanner.scanHost('192.168.1.1', 80, 1000)

To get network info

  //Returns `LSNetworkInfo`
  const networkInfo = await LanPortScanner.getNetworkInfo()

API

Types

LSConfig

Used to scan multiple hosts/ports.

Property Type Description
networkInfo LSNetworkInfo Contains ip address and subnet mask to scan.
ports number[] or undefined Ports to scan default is: [80, 443]
timeout number or undefined Timeout for each thread in ms, default is: 1000 ms
threads number or undefined Number of threads, default is: 150

LSNetworkInfo

Used to grenerate ip ranges for scanning.

Property Type Description
ipAddress string IP Address
subnetMask string Subnet mask

LSNetworkInfoExtra

Contains ip ranges for scanning purpose.

Property Type Description
ipAddress string IP Address
subnetMask string Subnet mask.
subnetConv string A CIDR prefix length for a valid IPv4 netmask or null if the netmask is not valid.
firstHost string The network address for a given IPv4 interface and netmask in CIDR notation.
lastHost string The broadcast address for a given IPv4 interface and netmask in CIDR notation.
firstHostHex string First host address in hex represantation.
lastHostHex string Last host address in hex represantation.
ipRange string[] Array of ip addresses.

LSSingleScanResult

Returns after host/port found.

Property Type Description
ip string IP Address
port number Subnet mask

LSScanResult

Returns after scan complete.

Property Type Description
ip string IP Address
ports number[] Subnet mask

Methods

getNetworkInfo()

Returns LSNetworkInfo object.

Example:

 const networkInfo = await LanPortScanner.getNetworkInfo()

getNetworkInfo()

Takes LSNetworkInfo and scan all hosts for specified ports.

Example:

 const networkInfo = await LanPortScanner.getNetworkInfo()

 let config: LSConfig = {
   networkInfo: networkInfo,
   ports: [80, 8085], //Specify port here
   timeout: 1000, //Timeout for each thread in ms
   threads: 150 //Number of threads
 }
 LanPortScanner.startScan(config, (totalHosts: number, hostScanned: number) => {
   console.log(hostScanned / totalHosts) //Show progress
 }, (result) => {
   console.log(result) //This will call after new ip/port found.
 }, (results) => {
   console.log(results) // This will call after scan end.
 })

generateIPRange()

Takes LSNetworkInfo, generates ip address, ports array and return LSNetworkInfoExtra object.

Example:

  const networkInfo = await LanPortScanner.getNetworkInfo()
  const ipRangeInfo = generateIPRange(config.networkInfo)

scanHost()

Scan single host with port, returns LSSingleScanResult

Example:

  let result = await LanPortScanner.scanHost('192.168.1.1', 80, 1000)

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Credits

Shift8 Web for awsome tutorial.

react-native-netinfo by The React Native Community

Local area icons created by Eucalyp - Flaticon

About

A simple port scanner for react native.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 33.5%
  • Java 31.1%
  • Objective-C 20.1%
  • JavaScript 9.1%
  • Ruby 4.5%
  • Starlark 1.7%