public static NbnsRecordNBSTAT Get(IPAddress target, IPAddress localAddress, int attempts = 2, int timeout = 1000) { if (localAddress == null || localAddress.AddressFamily != AddressFamily.InterNetwork) throw new Exception("invalid local address"); var request = new NbnsPacket(); request.Questions = new[] {new NbnsQuestion {Type = NbnsCodes.QTypes.NbStat}}; var responsePacket = request.Send(target, 137, localAddress, attempts, timeout); if (responsePacket.Header.ResultCode != NbnsCodes.RCodes.NoError) throw new CfnException(responsePacket.Header.ResultCode.GetThrowMessage()); return responsePacket.Answers.First().Record as NbnsRecordNBSTAT; }
public static Task<NbnsRecordNB.AddressEntryRecord[]> Addresses(string hostname, Nic localAddress, int attempts = 2, int timeout = 1000) { if (localAddress == null || localAddress.Ip.V4.IsSupported == false || localAddress.Ip.V4.PrimaryUnicast == null) throw new Exception("invalid local address"); var localUnicast = localAddress.Ip.V4.PrimaryUnicast; var request = new NbnsPacket(); request.Header.RecursionDesired = true; request.Header.Broadcast = true; request.Questions = new[] {new NbnsQuestion {Type = NbnsCodes.QTypes.Nb, Name = hostname.ToUpper()}}; return request.SendAsync(localUnicast.Network.BroadcastAddress, 137, localUnicast.Address, attempts, timeout) .ContinueWith(t => { if (t.Exception != null) throw t.Exception.InnerException; NbnsPacket response = t.Result; if (response.Header.ResultCode != NbnsCodes.RCodes.NoError) throw new CfnException(response.Header.ResultCode.GetThrowMessage()); return ((NbnsRecordNB) (response.Answers.First().Record)).AddressEntries; }); }