[英]C# How to Access local network (192.168.x.x) within Docker containers
This is my first post here, I've looked across the internet in order to solve this issue but have no idea how to do this, as i am new to docker and not that great at networking (saying kindly).这是我在这里的第一篇文章,我浏览了互联网以解决这个问题,但不知道如何做到这一点,因为我是 docker 新手,并且不太擅长网络(善意地说)。
I need a way to access my host machines internal network IP which has been forwarded to a port that connects to a proxy server.我需要一种方法来访问我的主机内部网络 IP,该 IP 已转发到连接到代理服务器的端口。 so essentially 192.168.x.xx:5000 => someproxyserver.com now when setting up the SOCKS5 on my local machine or even in C# it is able to connect and it works.
所以基本上 192.168.x.xx:5000 => someproxyserver.com 现在在我的本地机器上设置 SOCKS5 或什至在 C# 中时,它能够连接并且可以工作。 but this is not the case with docker, again i am complete noob at docker, i have tried many things, but i can't seem to get my docker container to connect to the socks5 server.
但这不是 docker 的情况,我再次完全是 docker 的菜鸟,我尝试了很多东西,但我似乎无法让我的 docker 容器连接到socks5 服务器。
I even tried to run the docker container with --network=host
but i get an error (no route to host) Ideally i would not want to use --network host as i have many other containers connecting to a external network.我什至尝试使用
--network=host
运行--network=host
容器,但出现错误(没有到主机的路由)理想情况下,我不想使用 --network 主机,因为我有许多其他容器连接到外部网络。
var settings = new ProxySettings() {
Host = localIp,
Port = port
};
using (var proxyClientHandler = new ProxyClientHandler<Socks5>(settings)) {
using (var httpClient = new HttpClient(proxyClientHandler)) {
var response = await httpClient.GetStringAsync("https://api.ipify.org?format=json");
}
}
this is the C# code which i am using to connect to the SOCKS5 server.这是我用来连接到 SOCKS5 服务器的 C# 代码。
When using --network=host
使用
--network=host
without --network=host
没有
--network=host
我设法以某种方式完成了这项工作,没有包含任何运行命令,我相信这是由于我的防火墙阻止访问而失败的,这很奇怪,因为我确实允许访问它,但是在早些时候重新启动我的计算机后,它工作了:) 所以是的,如果有人偶然发现了这一点,请记住确保您的防火墙没有阻止对 docker 的访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.