Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以让ruby通过特定的iface发送网络流量吗?_Ruby_Network Programming - Fatal编程技术网

我可以让ruby通过特定的iface发送网络流量吗?

我可以让ruby通过特定的iface发送网络流量吗?,ruby,network-programming,Ruby,Network Programming,我正在编写一个脚本,获取外部IP地址以及有关每个iface的其他信息。我不知道如何让ruby通过特定的iface发送流量(例如eth0和wlan0)。我目前正在使用OpenURI库打开并将其读入变量 def get_external_ip begin open("http://whatismyip.org") { |f| return f.read } rescue return "none" end end 是否有任何方法可以在脚本运行时或从脚本本身(理想情况下)

我正在编写一个脚本,获取外部IP地址以及有关每个iface的其他信息。我不知道如何让ruby通过特定的iface发送流量(例如eth0和wlan0)。我目前正在使用OpenURI库打开并将其读入变量

def get_external_ip
  begin
    open("http://whatismyip.org") { |f| return f.read }
  rescue
    return "none"
  end
end
是否有任何方法可以在脚本运行时或从脚本本身(理想情况下)指定此选项?

您可以检查此选项。但我怀疑它能否在像
open
这样的高层次上实现。接口通常从路由表中选择,具体取决于目标IP,因此可能更容易修复/调整路由表