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

renew-ip

v1.2.3

Published

A module for renewing 4G/LTE IP addresses on tethered Android phones from Node JS.

Downloads

19

Readme

A simple remote 4G rotator script

What it does

This package allows a user to cycle an Android phones flight mode using Automate app and cloud messages. The result is automated 4G IP renewal. Not root required.

What you need

  1. A clean 4G capable Android phone (ie ideally not the one you use day to day to avoid any identity leaks via App session fingerprinting). Does not require root.
  2. A clean Google account not used for anything else to receive cloud messages.
  3. Automate app https://play.google.com/store/apps/details?id=com.llamalab.automate

Installation

Automate / Android

  1. Set your "Toggle Flight Mode" quick access icon to the first icon on your pull down list.
  2. Copy the two .flo scripts to your phone. (Note you might need to edit the Flow in step 19 & 43 (as per PDF) if your language pack calls Flight Mode something like "Airplane Mode" or "Aeroplane Mode" etc)
  3. In step 42 (as per PDF) "Cloud Receive", set the account to your clean Google account.
  4. Disable phone Wifi and start the Flow on your phone. After the flow is started you can exit Automate and it will stay running.
Example of dropdown

Dropdown

Application

Install the package:

$ npm install renew-ip

Option 1: Class Instantiation

Instantiate a new Router in your application.

An example is provided here, and also in the ./examples folder.

import { RenewableRouter, Router } from "renew-ip"

/**
 * @class Demonstration
 * @class An abstract demo of how to implement the package. Note that in practice you would import from `renew-ip` not `../src`.
 */
export class Demo {
  /**
   * Protected container for the router.
   * @type {RenewableRouter}
   * @protected
   */
  protected _router: RenewableRouter = new Router()

  /**
   * Public method to toggle the handset's ip.
   *
   * @return {Promise<boolean>}
   */
  public async renewIp(): Promise<boolean> {
    return await this._router.renew()
  }

  /**
   * Example method for executing a web scrape with a fresh IP.
   *
   * @param {string} url
   * @return {Promise<void>}
   */
  public async scrape(url: string): Promise<void> {
    // Only continue if a fresh IP is obtained.
    if (await this.renewIp()) {
      // ... some sort of scrape task for example...
    }
    else {
      throw new Error(`Could not get a fresh ip, aborting scrape.`)
    }
  }
}

Option 2: Factory


import { useRouter  } from "renew-ip"

// Generate renewal function.
const renewIp: RenewIp = useRouter({
  maxAttempts: 5,
  delay: 1500
})

// ...

// Renew ip!
await renewIp()

Option 3: Binary

$ npx renew-ip 5 # (optional: attempts)

Configuration

IPData

To access IP reputation context you will need an IPData API key.

As you will generally be cycling less than 1500 times daily, the free plan will suffice.

Option 1: Create an .env file:

IP_RENEWAL_SECRET=<enter-your-automate-secret>
IP_RENEWAL_EMAIL=<enter-your-automate-email>
IP_RENEWAL_PRIORITY=normal
IP_RENEWAL_PAYLOAD=renew
IP_RENEWAL_MAX_ATTEMPTS=3
IP_RENEWAL_DELAY=1000
IPDATA_API_KEY=<your-ipdata-api-key>

Option 2: Pass a configuration object:

const config: RouterConfig = {
  secret: "<your-secret>",
  to: "<your-email>",
  priority: "normal",
  payload: "renew",
  maxAttempts: 3,
  delay: 1200
}
const router: RenewableRouter = new Router(config)

Recommendations

Recommend enabling the Auto Tether flow on the handset to avoid having to manually enable USB tethering each time you plug it in as a USB modem.

Additionally, you can use this via Wi-Fi Tethering, although it's quite a bit more complicated / less reliable to manage this in a Node script.

To avoid data excess, disable your phones' auto update over 4G and set to only update over Wi-Fi.

Running Remotely / Offshore

But what if you need to access 4G IPs in a different country?

Requirements
  • A cheap headless nano-PC such as an "Intel Compute Stick": https://www.intel.com/content/www/us/en/products/boards-kits/compute-stick.html
  • WireGuard: https://www.wireguard.com
  • 3Proxy with a local SOCKS5 config. Example: https://github.com/prescience-data/3proxy-config
Steps
  1. Configure your package to connect out via a VPN WireGuard (as listener) and 3proxy.
  2. Install the 3proxy config to create a local SOCKS5 proxy and install as a service.
  3. Setup WireGuard VPN as a client instance on your regular PC.
  4. VPN to the headless PC and you'll have access to its SOCKS5 proxy!

The optimal solution is to connect the Compute Stick to Wi-Fi (which WireGuard will use to connect in) and proxy connections out via 4G USB tethering to avoid congestion, but it is possible to go in and out via the same 4G provided you have enough bandwidth.

You can install some remote management software such as AnyDesk to remote into the headless PC whenever you need to fix or install something provided it remains connected to local internet.

Demo

When configured correctly, the package should run like this:

https://youtu.be/rbMXmME2TRs