- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试从 .NET Core MVC 应用程序发送局域网唤醒数据包。
如果应用程序托管在 Windows 主机上,它可以完美运行,但是当它在我的 Raspberry Pi 3(带有 Ubuntu Mate)上运行时,我收到以下错误:
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
An unhandled exception has occurred: Permission denied 255.255.255.255:40000
System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (0x80004005): Permission denied 255.255.255.255:40000
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at System.Net.Sockets.Socket.Connect(IPAddress address, Int32 port)
我正在使用它来发送 WOL 数据包:
public static bool WakeUp(string macAddress)
{
bool retVal = false;
try
{
byte[] mac = null;
// Parse string to byte array
string[] macDigits = null;
if (macAddress.Contains("-"))
{
macDigits = macAddress.Split('-');
}
else
{
macDigits = macAddress.Split(':');
}
if (macDigits.Length != 6)
{
//incorrect MAC address
}
else
{
mac = macDigits.Select(s => Convert.ToByte(s, 16)).ToArray();
}
if (mac != null)
{
// WOL packet is sent over UDP 255.255.255.0:40000.
UdpClient client = new UdpClient();
client.Client.Connect(IPAddress.Broadcast, 40000);
// WOL packet contains a 6-bytes trailer and 16 times a 6-bytes sequence containing the MAC address.
byte[] packet = new byte[17 * 6];
// Trailer of 6 times 0xFF.
for (int i = 0; i < 6; i++)
packet[i] = 0xFF;
// Body of magic packet contains 16 times the MAC address.
for (int i = 1; i <= 16; i++)
for (int j = 0; j < 6; j++)
packet[i * 6 + j] = mac[j];
// Submit
int result = client.Client.Send(packet);
if (result > 0)
{
retVal = true;
}
}
}
catch (Exception ex)
{
throw;
}
return retVal;
}
出于测试目的,我将端口更改为 2050 -> 同样的错误。
为了以防万一,这是 Program.cs 的内容
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel()
.UseUrls("http://*:80")
.UseContentRoot(Directory.GetCurrentDirectory())
.Build();
}
知道这是什么原因吗?应用程序的其余部分按预期工作。
最佳答案
启用广播后对我有用:
// UdpClient client = new UdpClient();
client.EnableBroadcast = true;
关于linux - 在 ubuntu 上无法使用 .NET Core 在 LAN 上发送唤醒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45642356/
我必须根据该 LAN 上的 ip 地址解析 LAN 中设备的主机名。我有一些代码适用于外部 IP 地址,但不适用于内部连接的设备。 下面我附上了代码。 如果您有任何想法从 iOS/OSX 中的 IP
我想在 ubuntu 机器上安装 Git 作为 git_server 并且局域网中的用户是 windows 机器(使用 eclipse 进行开发)我该如何配置我的局域网? 最佳答案 设置局域网 最简单
在 C# 中,我想在运行时获取笔记本电脑的有线 LAN 连接列表,但我不需要任何 wifi 或无线 LAN。 我使用了多种方法来获取网络列表:- 管理类: ManagementClass objMC
我正在使用主板(MSI Gaming主板)和两个支持NIC卡的e1000e驱动程序构建自定义操作系统。我想使用NIC卡中的端口而不是板载端口。 为了禁用板载端口,我尝试使用 70-persistanc
我想通过 LAN 广播字符串,但是当我将客户端代码中的服务器 IP 更改为 255.255.255.255 时,它不会广播。我应该怎么做才能通过 LAN 广播字符串?我应该在客户端代码中做什么,以便不
我正在设置一个 Apache Ignite 集群,当超过两个节点通过 LAN 交换机连接时,很难保持拓扑事件。日志中报告了许多警告和问题,但我想知道开始尝试隔离问题的正确步骤是什么?两个方向的 Pin
直到最近,我还设置了一堆虚拟站点,如下所示: ... 这适用于在我使用 Linux 桌面的本地机器上进行测试。为了测试 MS 和资源管理器如何从我的 Windows 笔记本电脑显示我的页面,
使用多播组发送消息而不是将它们广播到特定端口有什么好处吗?我知道在广播时,其他不想要消息的计算机也会收到它们,但是它对性能/流量有多大影响?不关心的计算机不是立即转储消息吗? 作为一个附带问题,局域网
我一直试图将LAN上的计算机从关机状态唤醒。发送WOL请求的计算机是Windows 10计算机,而我尝试唤醒的计算机是Windows 10计算机。 我尝试了一些在Internet上找到的脚本,大多数脚
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
我有一个服务器(在我的笔记本电脑上运行的 java 应用程序)和一个客户端(在我的 android 智能手机上运行的 java 应用程序)。我正在尝试从我的客户端自动查找服务器的 IP 地址。 现在我
如何获取局域网中所有的IP地址和关联的主机名? 最佳答案 要获取接口(interface)和 IP 地址列表,请使用 getifaddrs()。 使用 ifa_addr->sa_family == A
我想检查 Linux 系统上是否插入了 LAN 电缆,/sys 或/proc 中是否有任何我可以检查的文件(我想在 C 中进行)? 最佳答案 要检查电缆是否已插入,您可以查看/sys/class/ne
在多次尝试失败后,我在这里问。每个人都不是编程问题,但我认为与社区相关。 我一直在尝试通过局域网上的手机访问我的 docker-compose 开发网站,就像这样 https://lan_server
我试图让通用链接在我的应用程序中作为 URL 方案的替代品工作,因为从 iOS 9 开始,系统看起来每次从 Safari 调用应用程序时都会显示一个警告对话框。我希望在使用通用链接时替换关联域中注册
有没有办法以编程方式进入 BIOS 并为支持 LAN 唤醒功能的机器打开该功能? 理想情况下,解决方案应该是跨 BIOS,但使用单独的解决方案来打击每个主要供应商也是可以的。 最佳答案 BIOS 配置
我想制作一个小型应用程序,从连接到串行端口的设备收集数据,并将其通过 LAN 传递到另一个应用程序,后者将其存储在数据库中。 我已经在一台 PC 上的一个应用程序中完成了此操作,因此实际上会将应用程序
我正在尝试总体上熟悉 SIEM 系统,并决定通过 Digital Ocean 建立一个 Elastic Stack。一切都很成功,我作为 localhost 的服务器正在生成日志。修补可视化和那些好东
几个月前我在博客上发现了这个 PowerShell 代码。它在不使用外部程序的情况下将 LAN 唤醒信号发送到您选择的 MAC 地址。我在博文上发表评论,并要求作者描述脚本背后的逻辑,因为我对此感到好
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我是一名优秀的程序员,十分优秀!