Beispiel #1
0
        /// <summary>Given a full hostname, return the word upto the first dot.</summary>
        /// <param name="fullHostname">the full hostname</param>
        /// <returns>the hostname to the first dot</returns>
        public static string SimpleHostname(string fullHostname)
        {
            if (InetAddresses.IsInetAddress(fullHostname))
            {
                return(fullHostname);
            }
            int offset = fullHostname.IndexOf('.');

            if (offset != -1)
            {
                return(Runtime.Substring(fullHostname, 0, offset));
            }
            return(fullHostname);
        }
Beispiel #2
0
 /// <summary>Accepts a collection of ip/cidr/host addresses</summary>
 /// <param name="hostEntries"/>
 /// <param name="addressFactory">addressFactory to convert host to InetAddress</param>
 public MachineList(ICollection <string> hostEntries, MachineList.InetAddressFactory
                    addressFactory)
 {
     this.addressFactory = addressFactory;
     if (hostEntries != null)
     {
         if ((hostEntries.Count == 1) && (hostEntries.Contains(WildcardValue)))
         {
             all           = true;
             ipAddresses   = null;
             hostNames     = null;
             cidrAddresses = null;
         }
         else
         {
             all = false;
             ICollection <string>           ips   = new HashSet <string>();
             IList <SubnetUtils.SubnetInfo> cidrs = new List <SubnetUtils.SubnetInfo>();
             ICollection <string>           hosts = new HashSet <string>();
             foreach (string hostEntry in hostEntries)
             {
                 //ip address range
                 if (hostEntry.IndexOf("/") > -1)
                 {
                     try
                     {
                         SubnetUtils subnet = new SubnetUtils(hostEntry);
                         subnet.SetInclusiveHostCount(true);
                         cidrs.AddItem(subnet.GetInfo());
                     }
                     catch (ArgumentException e)
                     {
                         Log.Warn("Invalid CIDR syntax : " + hostEntry);
                         throw;
                     }
                 }
                 else
                 {
                     if (InetAddresses.IsInetAddress(hostEntry))
                     {
                         //ip address
                         ips.AddItem(hostEntry);
                     }
                     else
                     {
                         //hostname
                         hosts.AddItem(hostEntry);
                     }
                 }
             }
             ipAddresses   = (ips.Count > 0) ? ips : null;
             cidrAddresses = (cidrs.Count > 0) ? cidrs : null;
             hostNames     = (hosts.Count > 0) ? hosts : null;
         }
     }
     else
     {
         all           = false;
         ipAddresses   = null;
         hostNames     = null;
         cidrAddresses = null;
     }
 }