通过以太网电缆在计算机之间进行通信 [英] Communicate between computers through Ethernet cable

查看:31
本文介绍了通过以太网电缆在计算机之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用以太网电缆连接两台计算机而无需用户通过控制面板设置 LAN,然后在我的应用程序的两个实例之间传输数据 - 每台计算机上运行一个.

I want to connect two computers with an Ethernet cable without the user having to set up a LAN through the Control Panel and then transfer data between two instances of my app - one running on each computer.

一旦我与每台计算机的 IP 地址建立了连接,我就知道我可以轻松使用套接字、管道(?)、WCF 传输文件……但是两台计算机都是也通过 wifi 连接到路由器,那么我怎么能以某种方式告诉计算机对于特定的 IP 地址 - 请使用电缆?(我可能把所有这些都弄错了.请随时纠正我.)

As soon as I have a connection with an IP address for each computer, I know I can easily transfer a file by using Sockets, Pipes(?), WCF... But both computers are also connected via wifi to a router, so how can I somehow tell the computer that for a specific IP address - please use the cable? (I might be getting all of this wrong. Please feel free to correct me.)

我可以使用 UWP 应用或 .net (Winform/WPF) 应用.两种技术都很好.但这必须在代码中完成,而不是由用户通过控制面板设置 LAN.此外,IPv6 也很好.

I can use a UWP app or a .net (Winform/WPF) app. Either technology is fine. But this must be done in code, not by the users setting up a LAN through the Control Panel. Also, IPv6 is fine too.

推荐答案

System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()开始.

过滤掉 Type=EtherNet 接口并确保它们已启动.您可能还需要注意虚拟适配器等.

Filter out the Type=EtherNet interfaces and make sure they're Up. You may also have to watch out for virtual adapters etc.

您可以从所选的适配器中获取地址信息等.IPV4 地址可能足以让您入门.

From the selected adapter you can get Address Information etc. The IPV4 address should probably be enough to get you started.

这篇关于通过以太网电缆在计算机之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆