npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-lan-port-scanner

v1.4.2

Published

A simple port scanner for react native.

Downloads

282

Readme

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 as dependency. Please follow below steps to install:

yarn add gajjartejas/react-native-tcp react-native-lan-port-scanner

or

npm install gajjartejas/react-native-tcp react-native-lan-port-scanner

after you have to install pods

npx pod-install

For Android

You have to add below permission to AndroidManifest.xml file


<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

For iOS

Make a sure you have to add NSExceptionAllowsInsecureHTTPLoads to localhost in case of insecure connection info.plist.


<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>localhost</key>
    <dict>
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
    </dict>
  </dict>
</dict>

Usage

Scan network's hosts with specific ports

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

//Returns `LSNetworkInfo`
const networkInfo = await LanPortScanner.getNetworkInfo();
const config1: LSScanConfig = {
  networkInfo: networkInfo,
  ports: [80, 8085], //Specify port here
  timeout: 1000, //Timeout for each thread in ms
  threads: 150, //Number of threads
};

//OR

const ipRange = ['192.168.1.1', '192.168.1.112'];
let config2: LSScanConfig = {
  ipRange: ipRange, //If you provide this params then it will only scan provided ipRange.
  ports: [80, 8085], //Specify port here
  timeout: 1000, //Timeout for each thread in ms
  threads: 150, //Number of threads
};

//Either config1 or config2 required
const cancelScanHandle = LanPortScanner.startScan(
  config1, //or config2
  (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.
  }
);

//You can cancel scan later
setTimeout(() => {
  cancelScanHandle();
}, 5000);

To scan specific 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

LSScanConfig

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: [80, 443] | | timeout | number or undefined | Timeout for each thread in ms, default: 1000 ms | | threads | number or undefined | Number of threads, default: 150 | | logging | boolean | Enable or disable logging, default: false |

LSNetworkInfo

Used to generate 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 or null | 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 representation. | | lastHostHex | string | Last host address in hex representation. | | 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.

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:

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

TODO

  • Better scan handling and canceling.
  • Add abort signal for cancelling.

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


Made with create-react-native-library