public static Ethernet[] GetNetworkDevices() { NetworkInterface[] ifaces = NetworkInterface.GetAllNetworkInterfaces(); Ethernet[] ethernets = new Ethernet[ifaces.Length]; try { int count = 0; foreach (NetworkInterface iface in ifaces) { String ip = "0.0.0.0"; String mask = "255.255.255.255"; IPInterfaceProperties properties = iface.GetIPProperties(); foreach (UnicastIPAddressInformation unicast in properties.UnicastAddresses) { if (unicast.Address.AddressFamily == AddressFamily.InterNetwork) { ip = unicast.Address.ToString(); mask = unicast.IPv4Mask.ToString(); break; } } ethernets[count] = new Ethernet(iface.Name, ip, mask, iface.GetIPv4Statistics().BytesReceived, iface.GetIPv4Statistics().BytesSent); count++; } } catch (Exception e) { LogMan.AddLog("Error fetching Network Devices: " + e.Message); } return(ethernets); }
public static string Read(string KeyName) { // Opening the registry key RegistryKey rk = Registry.LocalMachine; // Open a subKey as read-only RegistryKey sk1 = rk.OpenSubKey("SOFTWARE\\Teske Virtual System\\" + ProgramBase); // If the RegistrySubKey doesn't exist -> (null) if (sk1 == null) { return(null); } else { try { // If the RegistryKey exists I get its value // or null is returned. return((string)sk1.GetValue(KeyName.ToUpper())); } catch (Exception e) { LogMan.AddLog("Error Reading registry " + KeyName.ToUpper() + " : " + e.ToString()); return(null); } } }
public static JObject _CallAPI(String method, NameValueCollection data) { String result = ""; JObject output; try { if (data == null) { data = new NameValueCollection(); } if (SessionKey != null) { data.Add(new NameValueCollection() { { "sessionkey", SessionKey } }); } using (WebClient client = new WebClient()) { result = System.Text.Encoding.UTF8.GetString(client.UploadValues(APIURL + "/api/" + method, data)); } output = JsonConvert.DeserializeObject <JObject>(result); } catch (Exception e) { LogMan.AddDebug("Error on _CallAPI: " + e.Message); result = "{\"status\":\"NOK\",\"error\":\"INTERNAL\"}"; output = JsonConvert.DeserializeObject <JObject>(result); } return(output); }
public static bool Write(string KeyName, object Value) { try { RegistryKey rk = Registry.LocalMachine; RegistryKey sk1 = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Teske Virtual System\\" + ProgramBase, RegistryKeyPermissionCheck.ReadWriteSubTree); sk1.SetValue(KeyName.ToUpper(), Value); return(true); } catch (Exception e) { LogMan.AddLog("Error writting registry " + KeyName.ToUpper() + " : " + e.ToString()); return(false); } }
public static Boolean SendMachine(MachineData m) { JObject data = _CallAPI("updatemachine", new NameValueCollection() { { "machinedata", m.ToJSON() } }); if (data["status"].ToString().Equals("OK")) { MachineUUID = data["machineuuid"].ToString(); return(true); } else { LogMan.AddLog("Error: " + data.ToString()); return(false); } }