Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multiplex

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiplex

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Multiplex

Multiplex gently monkey-patches TCPSocket to bind a Net::HTTP request to a non-default local IP address.

If you are craving cURL's --interface option to fire HTTP requests over multiple local IPs and are looking for a native Ruby solution, this is what you need.

tellier

Usage

Say the IP of your default interface is 10.1.1.2 and you have a second interface bound to 10.1.1.3.

require 'multiplex'
uri = URI.parse('http://jsonip.com')

Net::HTTP.bind 10.1.1.3 do
  res = Net::HTTP.get_response(uri)
  puts JSON.parse(res.body)['ip'] # 10.1.1.3
end

res = Net::HTTP.get_response(uri)
puts JSON.parse(res.body)['ip'] # 10.1.1.2

Alternatively, you can bind without a block and then unbind manually:

Net::HTTP.bind 10.1.1.3

res = Net::HTTP.get_response(uri)
puts JSON.parse(res.body)['ip'] # 10.1.1.3

Net::HTTP.unbind

res = Net::HTTP.get_response(uri)
puts JSON.parse(res.body)['ip'] # 10.1.1.2

FAQs

Package last updated on 18 Mar 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc