我将修改在Rosetta Code上找到的脚本,该脚本将根据http://api.macvendors.com上的出色api检查MAC地址。
我可以在Python和Go中做到这一点,但是没有问题,但是在C#中(因为它必须通过Icon通过桌面运行)我遇到了问题……最重要的是,代码对我来说没有多大意义。我从这里省略了“正在使用...”行
class Program
{
static async Task<string> LookupMac(string MacAddress)
{
var uri = new Uri("http://api.macvendors.com/" + WebUtility.UrlEncode(MacAddress));
using (var wc = new HttpClient())
return await wc.GetStringAsync(uri);
}
static void Main(string[] args)
{
foreach (var mac in new string[] { "88:53:2E:67:07:BE", "FC:FB:FB:01:FA:21", "D4:F4:6F:C9:EF:8D" })
Console.WriteLine(mac + "\t" + LookupMac(mac).Result);
Console.ReadLine();
}
}
我在整个异步方面都崩溃了!当我尝试运行代码时,这是Vis Studio的错误消息:
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at GetMacVend.Program.Main(String[] args) in C:\Users\wildm\VisC#\GetMacVend\GetMacVend\Program.cs:line 24
Inner Exception 1:
TaskCanceledException: A task was canceled.