Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YumaInaura opened this issue Nov 2, 2019 · 0 comments

Comments

@YumaInaura
Copy link
Owner

コンソールで 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant