Exemplo n.º 1
0
 public string getMyMachineInfo() {
     string myInfo = "";
     try
     {
         NetworkMap connectedDev = new NetworkMap();
         LAN mymachine = new LAN();
        mymachine = connectedDev.getMyMachineInfo();
         myInfo = JsonConvert.SerializeObject(mymachine);
     }
     catch (Exception ex)
     {
         ErrorTracker.WriteErrorLog("networkmap.cs", "getMyMachineInfo", "", ex.Message, ex.StackTrace, "ERROR");
     }
     return myInfo;
 }
Exemplo n.º 2
0
        public static LAN getMachineInfo()
        {
            LAN objlan = new LAN();

            IPHostEntry iphostentry = Dns.GetHostByName(Dns.GetHostName());

            objlan.HostName = iphostentry.HostName;
            objlan.MachineName = Dns.GetHostName();

            foreach (IPAddress ipaddress in iphostentry.AddressList)
            {
                objlan.IPAddress = Convert.ToString(ipaddress);
                objlan.MACAddress = Convert.ToString(GetMacAddress(ipaddress));
                objlan.AddressFamily = Convert.ToString(ipaddress.AddressFamily);
            }

            objlan.Status = "Active";

            return objlan;
        }
Exemplo n.º 3
0
        public static List<LAN> getLAN()
        {
            //local fields
            List<LAN> networkComputers = new List<LAN>();
            const int MAX_PREFERRED_LENGTH = -1;
            int SV_TYPE_WORKSTATION = 1;
            int SV_TYPE_SERVER = 2;
            IntPtr buffer = IntPtr.Zero;
            IntPtr tmpBuffer = IntPtr.Zero;
            int entriesRead = 0;
            int totalEntries = 0;
            int resHandle = 0;
            int sizeofINFO = Marshal.SizeOf(typeof(_SERVER_INFO_100));

            try
            {
                int ret = NetServerEnum(null, 100, ref buffer, MAX_PREFERRED_LENGTH, out entriesRead, out totalEntries, SV_TYPE_WORKSTATION | SV_TYPE_SERVER, null, out resHandle);
                if (ret == 0)
                {
                    for (int i = 0; i < totalEntries; i++)
                    {
                        tmpBuffer = new IntPtr((int)buffer + (i * sizeofINFO));

                        _SERVER_INFO_100 svrInfo = (_SERVER_INFO_100)Marshal.PtrToStructure(tmpBuffer, typeof(_SERVER_INFO_100));

                        //add the PC names to the ArrayList
                        
                        LAN lan = new LAN();
                        IPHostEntry iphostentry = Dns.GetHostByName(svrInfo.sv100_name);

                        


                        lan.HostName = iphostentry.HostName;
                        lan.MachineName = svrInfo.sv100_name;

                        foreach (IPAddress ipaddress in iphostentry.AddressList)
                        {

                            ////
                            //string strRoot = @"\\\\" + Convert.ToString(ipaddress) + "\\root\\cimv2";

                            //ManagementScope scope = new ManagementScope(strRoot);
                            //scope.Connect();

                            //// Use this code if you are connecting with a 
                            //// different user name and password:
                            ////
                            //// ManagementScope scope = 
                            ////    new ManagementScope(
                            ////        "\\\\FullComputerName\\root\\cimv2", options);
                            //// scope.Connect();

                            ////Query system for Operating System information
                            //ObjectQuery query = new ObjectQuery(
                            //    "SELECT * FROM Win32_OperatingSystem");
                            //ManagementObjectSearcher searcher =
                            //    new ManagementObjectSearcher(scope, query);

                            //ManagementObjectCollection queryCollection = searcher.Get();
                            //foreach (ManagementObject m in queryCollection)
                            //{
                            //    // Display the remote computer information
                            //    //Console.WriteLine("Computer Name : {0}", 
                            //    //    m["csname"]);
                            //    //Console.WriteLine("Windows Directory : {0}", 
                            //    //    m["WindowsDirectory"]);
                            //    //Console.WriteLine("Operating System: {0}",  
                            //    //    m["Caption"]);
                            //    //Console.WriteLine("Version: {0}", m["Version"]);
                            //    //Console.WriteLine("Manufacturer : {0}", 
                            //    //    m["Manufacturer"]);
                            //}
                            
                            lan.IPAddress = Convert.ToString(ipaddress);
                            lan.MACAddress = Convert.ToString(GetMacAddress(ipaddress));
                            lan.AddressFamily = Convert.ToString(ipaddress.AddressFamily);

                        }
                        lan.FriendlyName = string.Empty;
                        lan.Status = "Active";
                        if (getMachineInfo().IPAddress != lan.IPAddress && lan.MACAddress != "000000000000")
                        {
                            networkComputers.Add(lan);    
                        }
                        
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                NetApiBufferFree(buffer);
            }
            //return entries found
            return networkComputers;

        }