简体   繁体   English

C# 如何在 Docker 容器中访问本地网络 (192.168.xx)

[英]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.

相关问题 C# 程序侦听 0.0.0.0 但不是 192.168.xx - C# Program Listening on 0.0.0.0 but not 192.168.x.x 如何仅在 C# 中访问 X 坐标? - how to access to the X coordinate only in C#? 如何将 C# 项目与放置在服务器(非本地网络)上的 Access 数据库连接起来进行编辑和查看? - how to connect a C# project with Access database placed on server (NOT local network) to edit and view? 如何在连接到本地网络的设备上访问API并调试C#中的代码 - How to Access Your APIs on devices connected to your local network and Debug the the code in C# 如何从Internet访问本地网络中的服务器 - how to access server within local network from internet 如何使用c#以编程方式将x509证书添加到本地计算机存储 - How to programmatically add x509 certificate to local machine store using c# 如何使用C#访问网络路径 - How to Access the network path using C# C#:如何将字符串“[[&#39;x&#39;,&#39;x&#39;],[&#39;x&#39;,&#39;x&#39;]]”转换为没有Split()的数组? - C#: How to transform String “[['x','x'],['x','x']]” into an Array without Split()ing? 如何从3个数组中创建一个x的锯齿数组c# - How to create a jagged array x by x from 3 arrays c# 星号:来自“ 192.168.x.xxx”的连接尝试无法验证 - Asterisk: Connect attempt from '192.168.x.xxx' unable to authenticate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM