- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我试图在所有接口(interface)上发送一个 WOL 包以唤醒网关(这是 DHCP 服务器,所以机器还没有 IP)。
而且我似乎只能将套接字绑定(bind)到 IP 和端口对...
所以问题是:如何创建绑定(bind)到没有 IP 的 NIC 的套接字(或其他东西)?(任何语言都可以。首选c#)
@ctacke:我知道 WOL 是通过 MAC 地址完成的...我的问题是 Windows 只在 NIC 上发送 UDP 广播,Windows 认为这是主 NIC(甚至不是默认路由的 NIC我的 Vista 机器)。而且我似乎找不到将套接字绑定(bind)到没有 IP 地址的接口(interface)的方法。 (就像 DHCP 客户端那样做)
@Arnout:为什么不呢?客户端知道网关的 MAC 地址。我只想像 DHCP 客户端最初那样发送 WOL 数据包...(DHCP 发现数据包声称来自 0.0.0.0)我不介意是否必须逐字节构建整个数据包...
最佳答案
看来我找到了解决办法。可以使用 winpcap 将数据包注入(inject)任何接口(interface)。.net 有很好的包装器:http://www.tamirgal.com/home/dev.aspx?Item=SharpPcap
(我更喜欢不需要安装额外库的解决方案...)
更新:这是我在所有接口(interface)上发送 WOL 数据包的结果:
//You need SharpPcap for this to work
private void WakeFunction(string MAC_ADDRESS)
{
/* Retrieve the device list */
Tamir.IPLib.PcapDeviceList devices = Tamir.IPLib.SharpPcap.GetAllDevices();
/*If no device exists, print error */
if (devices.Count < 1)
{
Console.WriteLine("No device found on this machine");
return;
}
foreach (NetworkDevice device in devices)
{
//Open the device
device.PcapOpen();
//A magic packet is a broadcast frame containing anywhere within its payload: 6 bytes of ones
//(resulting in hexadecimal FF FF FF FF FF FF), followed by sixteen repetitions
byte[] bytes = new byte[120];
int counter = 0;
for (int y = 0; y < 6; y++)
bytes[counter++] = 0xFF;
//now repeat MAC 16 times
for (int y = 0; y < 16; y++)
{
int i = 0;
for (int z = 0; z < 6; z++)
{
bytes[counter++] =
byte.Parse(MAC_ADDRESS.Substring(i, 2),
NumberStyles.HexNumber);
i += 2;
}
}
byte[] etherheader = new byte[54];//If you say so...
var myPacket = new Tamir.IPLib.Packets.UDPPacket(EthernetFields_Fields.ETH_HEADER_LEN, etherheader);
//Ethernet
myPacket.DestinationHwAddress = "FFFFFFFFFFFFF";//it's buggy if you don't have lots of "F"s... (I don't really understand it...)
try { myPacket.SourceHwAddress = device.MacAddress; }
catch { myPacket.SourceHwAddress = "0ABCDEF"; }//whatever
myPacket.EthernetProtocol = EthernetProtocols_Fields.IP;
//IP
myPacket.DestinationAddress = "255.255.255.255";
try { myPacket.SourceAddress = device.IpAddress; }
catch { myPacket.SourceAddress = "0.0.0.0"; }
myPacket.IPProtocol = IPProtocols_Fields.UDP;
myPacket.TimeToLive = 50;
myPacket.Id = 100;
myPacket.Version = 4;
myPacket.IPTotalLength = bytes.Length - EthernetFields_Fields.ETH_HEADER_LEN; //Set the correct IP length
myPacket.IPHeaderLength = IPFields_Fields.IP_HEADER_LEN;
//UDP
myPacket.SourcePort = 9;
myPacket.DestinationPort = 9;
myPacket.UDPLength = UDPFields_Fields.UDP_HEADER_LEN;
myPacket.UDPData = bytes;
myPacket.ComputeIPChecksum();
myPacket.ComputeUDPChecksum();
try
{
//Send the packet out the network device
device.PcapSendPacket(myPacket);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
device.PcapClose();
}
}
关于c# - 如何通过没有 IP 地址的网卡发送 WOL 包(或任何东西)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/445411/
我想检测是否可以进行局域网唤醒。 在我的路由器(Tomato 固件)上有一个包含信息的表格 - 当显示设备“事件(在 ARP 中)”时 - 可以通过 WOL(离线 Linux 电脑)打开该设备。 我想
不久前,我 [在 Google 的帮助下] 写了一个小的 WOL 脚本来打开我网络中的计算机。这是脚本: exec /usr/bin/python -x "$0" "$@" # node_lst =
我正在尝试在我的 C# 应用程序中接收 WOL 包。我想它为什么不起作用的问题与我运行 DD-WRT 的路由器如何广播包有关。 我用来接收UDP包的代码: UdpClient udp = new
我有一台工作中的计算机,有时我会从家里醒来以便访问它,但是当启动并从我们的 DHCP 服务器获取另一个 IP 地址时,我该如何访问它? 情况和我的“工作流程”如下: 我从家里的 PC 连接到办公室的
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我试图在所有接口(interface)上发送一个 WOL 包以唤醒网关(这是 DHCP 服务器,所以机器还没有 IP)。 而且我似乎只能将套接字绑定(bind)到 IP 和端口对... 所以问题是:如
你能给我完整的代码来通过网卡和 BIOS 的 WOL 选项打开联网计算机吗? 请提供所有详细信息并尝试给我工作代码。 最佳答案 using System; using System.Net.Socke
我想知道是否可以检查 WOL-request 是否已经 在计算机已开启的情况下收到。 (pInvoke,c#?) 如果计算机收到magic paket 并启动,Windows 会将相应的事件日志条目写
我是一名优秀的程序员,十分优秀!