Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Linq;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Management;
- namespace Client
- {
- class Program
- {
- static void Main(string[] args)
- {
- const int Port = 4800;
- string serverIp = "?";
- //Get all addresses
- string hostname = System.Net.Dns.GetHostName();
- IPHostEntry allLocalNetworkAddresses = Dns.Resolve(hostname);
- //Walk thru all network interfaces.
- foreach (IPAddress ip in allLocalNetworkAddresses.AddressList)
- {
- Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
- //Bind on port 0. The OS will give some port between 1025 and 5000.
- client.Bind(new IPEndPoint(ip, 0));
- //Create endpoint, broadcast.
- IPEndPoint AllEndPoint = new IPEndPoint(IPAddress.Broadcast, Port);
- //Allow sending broadcast messages
- client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
- //Send message to everyone on this network
- client.SendTo(new byte[] { 1 }, AllEndPoint);
- Console.Write("Client send '1' to " + AllEndPoint.ToString() + Environment.NewLine);
- try
- {
- //Create object for the server.
- IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
- EndPoint tempRemoteEP = (EndPoint)sender;
- byte[] buffer = new byte[1000];
- //Recieve from server. Don't wait more than 3000 milliseconds.
- client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 3000);
- //Recive message, save wherefrom in tempRemoteIp
- client.ReceiveFrom(buffer, ref tempRemoteEP);
- Console.Write("Client got '" + buffer[0] + "' from " + tempRemoteEP.ToString() + Environment.NewLine);
- //Get server IP (ugly)
- serverIp = tempRemoteEP.ToString().Split(":".ToCharArray(), 2)[0];
- //Don't try any more networkss
- break;
- }
- catch
- {
- //Timout. No server answered. Try next network.
- }
- }
- Console.Write("Service IP: " + serverIp + Environment.NewLine);
- try
- {
- ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Processor");
- foreach (ManagementObject queryObj in searcher.Get())
- {
- Console.WriteLine("-----------------------------------");
- Console.WriteLine("Win32_Processor instance");
- Console.WriteLine("-----------------------------------");
- Console.WriteLine("AddressWidth: {0}", queryObj["AddressWidth"]);
- Console.WriteLine("Architecture: {0}", queryObj["Architecture"]);
- Console.WriteLine("Availability: {0}", queryObj["Availability"]);
- Console.WriteLine("Caption: {0}", queryObj["Caption"]);
- Console.WriteLine("ConfigManagerErrorCode: {0}", queryObj["ConfigManagerErrorCode"]);
- Console.WriteLine("ConfigManagerUserConfig: {0}", queryObj["ConfigManagerUserConfig"]);
- Console.WriteLine("CpuStatus: {0}", queryObj["CpuStatus"]);
- Console.WriteLine("CreationClassName: {0}", queryObj["CreationClassName"]);
- Console.WriteLine("CurrentClockSpeed: {0}", queryObj["CurrentClockSpeed"]);
- Console.WriteLine("CurrentVoltage: {0}", queryObj["CurrentVoltage"]);
- Console.WriteLine("DataWidth: {0}", queryObj["DataWidth"]);
- Console.WriteLine("Description: {0}", queryObj["Description"]);
- Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
- Console.WriteLine("ErrorCleared: {0}", queryObj["ErrorCleared"]);
- Console.WriteLine("ErrorDescription: {0}", queryObj["ErrorDescription"]);
- Console.WriteLine("ExtClock: {0}", queryObj["ExtClock"]);
- Console.WriteLine("Family: {0}", queryObj["Family"]);
- Console.WriteLine("InstallDate: {0}", queryObj["InstallDate"]);
- Console.WriteLine("L2CacheSize: {0}", queryObj["L2CacheSize"]);
- Console.WriteLine("L2CacheSpeed: {0}", queryObj["L2CacheSpeed"]);
- Console.WriteLine("L3CacheSize: {0}", queryObj["L3CacheSize"]);
- Console.WriteLine("L3CacheSpeed: {0}", queryObj["L3CacheSpeed"]);
- Console.WriteLine("LastErrorCode: {0}", queryObj["LastErrorCode"]);
- Console.WriteLine("Level: {0}", queryObj["Level"]);
- Console.WriteLine("LoadPercentage: {0}", queryObj["LoadPercentage"]);
- Console.WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
- Console.WriteLine("MaxClockSpeed: {0}", queryObj["MaxClockSpeed"]);
- Console.WriteLine("Name: {0}", queryObj["Name"]);
- Console.WriteLine("NumberOfCores: {0}", queryObj["NumberOfCores"]);
- Console.WriteLine("NumberOfLogicalProcessors: {0}", queryObj["NumberOfLogicalProcessors"]);
- Console.WriteLine("OtherFamilyDescription: {0}", queryObj["OtherFamilyDescription"]);
- Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
- if (queryObj["PowerManagementCapabilities"] == null)
- Console.WriteLine("PowerManagementCapabilities: {0}", queryObj["PowerManagementCapabilities"]);
- else
- {
- UInt16[] arrPowerManagementCapabilities = (UInt16[])(queryObj["PowerManagementCapabilities"]);
- foreach (UInt16 arrValue in arrPowerManagementCapabilities)
- {
- Console.WriteLine("PowerManagementCapabilities: {0}", arrValue);
- }
- }
- Console.WriteLine("PowerManagementSupported: {0}", queryObj["PowerManagementSupported"]);
- Console.WriteLine("ProcessorId: {0}", queryObj["ProcessorId"]);
- Console.WriteLine("ProcessorType: {0}", queryObj["ProcessorType"]);
- Console.WriteLine("Revision: {0}", queryObj["Revision"]);
- Console.WriteLine("Role: {0}", queryObj["Role"]);
- Console.WriteLine("SecondLevelAddressTranslationExtensions: {0}", queryObj["SecondLevelAddressTranslationExtensions"]);
- Console.WriteLine("SocketDesignation: {0}", queryObj["SocketDesignation"]);
- Console.WriteLine("Status: {0}", queryObj["Status"]);
- Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);
- Console.WriteLine("Stepping: {0}", queryObj["Stepping"]);
- Console.WriteLine("SystemCreationClassName: {0}", queryObj["SystemCreationClassName"]);
- Console.WriteLine("SystemName: {0}", queryObj["SystemName"]);
- Console.WriteLine("UniqueId: {0}", queryObj["UniqueId"]);
- Console.WriteLine("UpgradeMethod: {0}", queryObj["UpgradeMethod"]);
- Console.WriteLine("Version: {0}", queryObj["Version"]);
- Console.WriteLine("VirtualizationFirmwareEnabled: {0}", queryObj["VirtualizationFirmwareEnabled"]);
- Console.WriteLine("VMMonitorModeExtensions: {0}", queryObj["VMMonitorModeExtensions"]);
- Console.WriteLine("VoltageCaps: {0}", queryObj["VoltageCaps"]);
- }
- }
- catch (ManagementException e)
- {
- Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment