我可以让ruby通过特定的iface发送网络流量吗?
我正在编写一个脚本,获取外部IP地址以及有关每个iface的其他信息。我不知道如何让ruby通过特定的iface发送流量(例如eth0和wlan0)。我目前正在使用OpenURI库打开并将其读入变量我可以让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 是否有任何方法可以在脚本运行时或从脚本本身(理想情况下)
def get_external_ip
begin
open("http://whatismyip.org") { |f| return f.read }
rescue
return "none"
end
end
是否有任何方法可以在脚本运行时或从脚本本身(理想情况下)指定此选项?您可以检查此选项。但我怀疑它能否在像open
这样的高层次上实现。接口通常从路由表中选择,具体取决于目标IP,因此可能更容易修复/调整路由表