0
0

More than 1 year has passed since last update.

#Ruby で local に SOCKS proxy を立てて ssh サーバーを踏み台に https 接続をする例 ( faraday + faraday_adapter_socks gem )

Last updated at Posted at 2019-11-02

コンソールで SOCSK proxy を起動しておく

ssh -vND 8888 user@host

gem Install

gem install faraday
gem install faraday_adapter_socks

Code

require 'faraday_adapter_socks'

options = { proxy: { uri: URI.parse("socks://127.0.0.1:8888") } }

url = 'https://httpbin.org/ip'

conn = Faraday.new(url, options) do |faraday|
  faraday.request :url_encoded
  faraday.adapter :net_http_socks  # please assign ":net_http_socks" adapter
end

response = JSON.parse(conn.get.body)
# => {"origin"=>"YYY.YYY.YYY.YYY., YYY.YYY.YYY.YYY"}

自分のIPアドレスが変わっていたら成功

🎉

元の問題

faraday で proxy を指定しても

Using socks proxy with auth leads to Faraday::ConnectionFailed: end of file reached

とエラーが返ってきて使えない。

Faraday and socks proxy with auth supporting · Issue #787 · lostisland/faraday

Ruby関係無しで curl で確認する例

$ https_proxy=socks://127.0.0.1:8888 curl https://httpbin.org/ip
{
  "origin": "YYY.YYY.YYY, YYY.YYY.YYY.YYY."
}

ところで Faradayの名前の由来ってなに?

【意味】ファラデー 《1791‐1867; 英国の物理学者》...

この人?なんだろうか

image

Faradayに似ているスターバックスを見つけました。めりーくりすま

image

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0