Example #1
0
        public static List <MachineEntity> GetNetWorkMachines()
        {
            ArrayList     alNetworkComputers = NetApi32.GetServerList(NetApi32.SV_101_TYPES.SV_TYPE_WORKSTATION | NetApi32.SV_101_TYPES.SV_TYPE_SERVER);
            var           returnList         = new List <MachineEntity>();
            MachineEntity machineentity      = null;
            string        computerName       = "";

            for (int nIndex = 0; nIndex < alNetworkComputers.Count; nIndex++)
            {
                computerName              = ((NetApi32.SERVER_INFO_101)alNetworkComputers[nIndex]).sv101_name;
                machineentity             = new MachineEntity();
                machineentity.MachineName = computerName;
                if (Dns.GetHostName() != computerName)
                {
                    try
                    {
                        machineentity.IPAddress = Dns.GetHostAddresses(computerName)[0].ToString();
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        machineentity.IPAddress = "NA";
                    }
                }
                else
                {
                    machineentity.IPAddress = GetLocalIPv4(NetworkInterfaceType.Ethernet);
                }
                returnList.Add(machineentity);
            }
            return(returnList);
        }
Example #2
0
 private List <MachineEntity> NetworkComputers()
 {
     return(NetApi32.GetNetWorkMachines());
 }