Under normal conditions it is not necessary to use this class to use jCIFS properly.

Under normal conditions it is not necessary to use this class to use jCIFS properly. Name resolusion is handled internally to the jcifs.smb package.

This class is a wrapper for both Jcifs.Netbios.NbtAddress and System.Net.IPAddress . The name resolution mechanisms used will systematically query all available configured resolution services including WINS, broadcasts, DNS, and LMHOSTS. See Setting Name Resolution Properties and the jcifs.resolveOrder property. Changing jCIFS name resolution properties can greatly affect the behavior of the client and may be necessary for proper operation.

This class should be used in favor of InetAddress to resolve hostnames on LANs and WANs that support a mixture of NetBIOS/WINS and DNS resolvable hosts.

示例#1
0
        /// <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);
        }
示例#2
0
		/// <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);
		}