Anyone Docs
  • 🔷The Documentation For Anyone
    • About
    • FAQ
  • 🔷Relay Setup
    • Get Started
    • Relay Operator Standards
    • Installation and Usage
      • Virtualization on Windows
      • Virtualization on macOS
      • Install Ubuntu Server 24.04
      • Server management with SSH in Windows and macOS
      • Install Anon on Linux
      • Firewall and Network Configurations
        • Router Port Forwarding
        • Install and Configure Firewall
      • Troubleshooting Common Issues
        • Diagnosing CGNAT and Public IPv4
        • Confirm ORPort Reachability
        • Configure IPv4 and IPv6
      • Advanced Configuration
        • Install Anon using the apt repository
          • Binary Verification
        • Install Anon in Docker
        • Install Anyone Exit Relay
          • Exit Relay Guidelines
        • DoS mitigation parameters
        • Update Anon and accept terms and conditions
        • Configure SOCKS5 Proxy for Anyone
  • 🔷Hardware Setup
    • Setup Guide
    • Router Mode Setup
    • Description and Specifications
    • Relay Control Panel Pages
      • Home
      • Network Settings
      • Relay Settings
      • Relay Family
      • Proxy Settings BETA
      • Change Password
      • Logs
      • Update
    • Hardware Updates
      • System Update (USB)
      • System Update (WebUI)
      • Anon Update (WebUI)
    • Troubleshooting and additional configuration
      • Router Port Forwarding
      • Diagnosing CGNAT and Public IPv4
  • 🔷Security and Privacy
    • VPS Hardening
  • 🔷Rewards Dashboard
    • Registering to the Rewards Program
    • Accessing the Rewards Dashboard
    • Using the Rewards Dashboard
    • Rewards Status
  • 🔷Anyone SDK
    • NPM SDK
      • Install NPM Package
      • Run as Library
        • Anon
        • AnonSocksClient
        • AnonControlClient
      • Run from CLI
      • Tutorials
        • Hello Anon World I
        • Hello Anon World II
        • Circuit Control I
        • Circuit Control II
    • Native SDK
      • Anyone Client Releases
      • MAN - Anon Manual
      • Tutorials
        • Anyone Services I
        • Anyone Services II
    • iOS SDK [Beta]
      • Manual Install - CocoaPods
  • 🔷Connect to Anyone
    • Connecting to Linux
      • [Beta] One-Click Linux Setup
    • Connecting to macOS
      • macOS with NPM
      • [Beta] One-Click macOS Setup
    • Connecting to Windows
      • [Beta] One-Click Windows Setup
    • Individual Applications with Anyone
    • Connect Through Hardware
  • 🔷Tokenomics
    • Introduction
    • Token Distribution
      • Token Outflow
      • Other Tokens
      • Multichain
    • Relay Rewards
      • Lock Requirement
      • Lock Adjustments
      • Reward Multipliers
    • Additional Roles
      • Authorities and Staking
      • Governance Voting
    • Premium Circuits
      • Premium Circuits
      • Premium Circuits: Metrics
    • Summary
      • Value Accrual Summary
      • Rewards Case Study
    • Appendix
      • M Derivation
      • Risk Equation Derivation
  • 🔷Resources
    • Community and Customer Support
    • Links
    • Token
    • Whitepaper
    • Roadmap
    • API
      • REST
      • [Future] GraphQL
Powered by GitBook
On this page
  • Anon Socks Client
  • Fetching our IP
  1. Anyone SDK
  2. NPM SDK
  3. Tutorials

Hello Anon World II

PreviousHello Anon World INextCircuit Control I

Last updated 7 months ago

In part II, we will introduce the AnonSocksClient and make our first request over the internet - fetching your (new) IP address! We will continue from the node module and codebase from Hello Anon World I.

Anon Socks Client

The AnonSocksClient is used to tunnel http(s) requests through the network. It provides implementations for get, post, delete and more that automatically use a running instance of the Anyone client. It can be imported much like the Anon library:

import { AnonSocksClient } from "@anyone-protocol/anyone-client";

and instantiated immediately after the instantiation of the main anon client, taking it as reference:

// ..imports and function statements..
const anon = new Anon({ displayLog: false, socksPort: 9050, controlPort: 9051 });
const anonSocksClient = new AnonSocksClient(anon);

For those coming in from part I, you'll notice some new arguments in the anon instantiation - these are optional arguments that become relevant when dealing with SOCKS routing, circuit control and debugging. Seen in this code snippet are the default values for each one.

What are SOCKS?

These SOCKS aren't for your feet! SOCKS is an acronym for Socket Secure - an internet protocol that allows you to route your traffic to a 'proxy server' (i.e., a server that sits in between you and your eventual, varied list of destinations).

Importantly, a SOCKS proxy server can run locally, listening to any requests made on a specific port (known as 'binding' to that port). In this case, the anon SOCKS process listens to any request made to the specified socksPort, forwards this through a circuit in the Anon network, and returns the result to whichever process makes the request.

Fetching our IP

Here, we will be calling anonSocksClient.get to fetch our IP through the network. We'll be using the public, free service at https://api.ipify.org, but you can choose any that works as an API! We will simply call 'get' on the API, await its result and print the result:

const response = await anonSocksClient.get('https://api.ipify.org?format=json');
console.log('Response:', response.data);

Let's see the AnonSocksClient setup and this logic in the full function (note that, for now, a short wait time is required after anon.start() and before making requests through the network).

import { Anon } from "@anyone-protocol/anyone-client";
import { AnonSocksClient } from "@anyone-protocol/anyone-client";

async function main() {
    const anon = new Anon();
    const anonSocksClient = new AnonSocksClient(anon);

    try {
        await anon.start();
        await new Promise(resolve => setTimeout(resolve, 15000));
        
        const response = await anonSocksClient.get('https://api.ipify.org?format=json');
        console.log('Response:', response.data);
        
    } catch(error) {
        console.log(error)
    } finally {
        await anon.stop()
    }
}

main()

Running node <programName>.js from the command line will show the same setup logs as before and then the result of the IP lookup! We're now, as far as external sites are concerned, coming out of Bayern, Germany. Cool!

See the full code on GitHub.

Now, lets look into more fine-tuned circuit control.

🔷
🧦