private static void NameResolutionTest2() { var naddr = NbtAddress.GetByName($"COCO4"); Out($"{naddr.GetHostName()}"); var auth = new NtlmPasswordAuthentication("", Info.UserName, Info.Password); var namedServer = new SmbFile($"smb://{Info.ServerIP}/", auth); var exists = namedServer.Exists(); var list = namedServer.ListFiles(); foreach (var smb in list) { Out($"{smb.GetName()}"); } }
public void GetByNameTest() { //NG: ローカルポートと共に、宛先ポートを変更してしまう。 //SharpCifs.Config.SetProperty("jcifs.netbios.lport", "2137"); //ローカルポートのみを変更する。ウェルノウンポートは管理者権限が必要なので。 SharpCifs.Config.SetProperty("jcifs.smb.client.lport", "2137"); var srvName1 = this.ServerName; var ipAddr = this.ServerIp; var nname = NbtAddress.GetByName(srvName1); var addrs = nname.GetInetAddress(); this.Out($"{srvName1} = {addrs}"); Assert.AreEqual(ipAddr, addrs.ToString()); nname = NbtAddress.GetByName(ipAddr); addrs = nname.GetInetAddress(); this.Out($"{ipAddr} = {nname.GetHostName()}"); Assert.AreEqual(ipAddr, addrs.ToString()); }
/// <exception cref="UnknownHostException"></exception> public static UniAddress[] GetAllByName(string hostname, bool possibleNtDomainOrWorkgroup) { object addr; int i; if (string.IsNullOrEmpty(hostname)) { throw new UnknownHostException(); } if (IsDotQuadIp(hostname)) { UniAddress[] addrs = new UniAddress[1]; addrs[0] = new UniAddress(NbtAddress.GetByName(hostname)); return(addrs); } for (i = 0; i < _resolveOrder.Length; i++) { try { switch (_resolveOrder[i]) { case ResolverLmhosts: { if ((addr = Lmhosts.GetByName(hostname)) == null) { continue; } break; } case ResolverWins: { if (hostname == NbtAddress.MasterBrowserName || hostname.Length > 15) { // invalid netbios name continue; } if (possibleNtDomainOrWorkgroup) { addr = LookupServerOrWorkgroup(hostname, NbtAddress.GetWinsAddress()); } else { addr = NbtAddress.GetByName(hostname, unchecked (0x20), null, NbtAddress.GetWinsAddress()); } break; } case ResolverBcast: { if (hostname.Length > 15) { // invalid netbios name continue; } try { if (possibleNtDomainOrWorkgroup) { NbtAddress[] iaddrs = LookupServerOrWorkgroup(hostname, _baddr); UniAddress[] addrs = new UniAddress[iaddrs.Length]; for (int ii = 0; ii < iaddrs.Length; ii++) { addrs[ii] = new UniAddress(iaddrs[ii]); } return(addrs); } else { addr = NbtAddress.GetByName(hostname, unchecked (0x20), null, _baddr); } } catch (Exception ex) { if (i == _resolveOrder.Length - 1) { throw ex; } else { continue; } } break; } case ResolverDns: { if (IsAllDigits(hostname)) { throw new UnknownHostException(hostname); } IPAddress[] iaddrs = Extensions.GetAddressesByName(hostname); if (iaddrs == null || iaddrs.Length == 0) { continue; } return(iaddrs.Select(iaddr => new UniAddress(iaddr)).ToArray()); } default: { // Success throw new UnknownHostException(hostname); } } UniAddress[] addrs1 = new UniAddress[1]; addrs1[0] = new UniAddress(addr); return(addrs1); } catch (IOException) { } } // Success // Failure throw new UnknownHostException(hostname); }