Skip to content

Port Leases

Port leases allow you to utilize our proxy services to connect to any TCP service, such as a database, without your database drivers needing to support SOCKS5 or deploying your service with any extra software.

TIP

Language specific client libraries are coming soon, for now we will utilize the JSON API.

Creating a port lease

Let's say we wanted to connect to a MySQL database using a proxy, but we there is no support for SOCKS5. We can request a port lease using Noble IP's Lease API.

js
import fetch from 'node-fetch';
import mysql from require('mysql');

const mysqlHost = 'mysql.company.com';
const mysqlPort = 3306;

const lease = await fetch("https://api.noble-ip.com/v1/leases", {
  method: "POST",
  headers: {
    "Content-Type": "application/json; charset=utf-8"
  },
  body: JSON.stringify({
    target_host: mysqlHost,
    target_port: mysqlPort,
    proxy_token: 'fp_NOBLETOKEN',
  }),
});

// MySQL database configuration
const connection = mysql.createConnection({
  host: lease.hostname,
  port: lease.port,
  user: 'your_username',
  password: 'your_password',
  database: 'your_database'
});

// Establish the connection
connection.connect((error) => {
  if (error) {
    console.error('Error connecting to the database: ', error);
    return;
  }
  console.log('Connected to the MySQL database.');
});
python
import mysql.connector
import requests

lease = requests.post("https://api.noble-ip.com/v1/leases", json={
    "target_host": "mysql.mycompany.com",
    "target_port": 3306,
    "proxy_token": 'fp_PROXYTOKEN',
}).json()

# MySQL database configuration
config = {
  'host': lease['hostname'],
  'port': lease['port'],
  'user': 'your_username',
  'password': 'your_password',
  'database': 'your_database'
}

# Establish the connection
connection = mysql.connector.connect(**config)

if connection.is_connected():
    print('Connected to the MySQL database.')
else:
    print('Failed to connect to the MySQL database.')
ruby
require 'mysql2'
require 'net/http'
require 'json'

url = URI.parse('https://api.noble-ip.com/v1/leases')
data = { 'target_host' => 'mysql.mycompany.com', 'target_port' => 3306, 'proxy_token' => 'fp_NOBLETOKEN' }

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url.path)
request.body = data.to_json
request['Content-Type'] = 'application/json'

response = http.request(request)
lease = JSON.parse(response.body)

# MySQL database configuration
client = Mysql2::Client.new(
  host: lease.hostname,
  port: lease.port
  username: 'your_username',
  password: 'your_password',
  database: 'your_database'
)

# Establish the connection
if client
  puts 'Connected to the MySQL database.'
else
  puts 'Failed to connect to the MySQL database.'
end