private void Form1_Load(object sender, EventArgs e) { NetworkItemObj = new NetworkItem(); /// change IP NetworkItemObj = NetworkConfig.GetNetworkItem(); Log(NetworkItemObj.Name + ", IP: " + NetworkItemObj.IP); NetworkWork(); ChangeIPServerWork(NewIP); ChangeIPServerMySql(NewIP); }
private void NetworkWork() { // read Network config var NetworkJsonText = File.ReadAllText("Data\\Network.json"); Dictionary <string, string> NetworkDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(NetworkJsonText); // check right IPv4 format foreach (KeyValuePair <string, string> Item in NetworkDictionary) { bool IsOK = InternetHelper.IsIPv4(Item.Value.Trim()); if (!IsOK) { LogError(string.Format("Item {0} = {1} is not IPv4 format. Check /Data/Network.json .", Item.Key, Item.Value)); return; // END work here } Log(string.Format("Check {0} = {1} is OK.", Item.Key, Item.Value)); } // check right IPv4 vs Gateway if (!InternetHelper.IsRightIPv4AndGateway(NetworkDictionary["IP"], NetworkDictionary["Gateway"])) { LogError("IPv4 not same Gateway, ex SAME.SAME.SAME.DIFFER ."); return; // END work here } // NewIP = NetworkDictionary["IP"]; // set data NetworkConfig.SetIP( NetworkItemObj.Name, NetworkDictionary["IP"], NetworkDictionary["Netmask"], NetworkDictionary["Gateway"] ); NetworkConfig.SetDNS( NetworkItemObj.Name, NetworkDictionary["DNS1"], NetworkDictionary["DNS2"] ); // wait some for win update //Thread.Sleep(1000); Log("Done. New IP For Verify: " + NetworkConfig.GetNetworkItem().IP); Log("My production performance/effeitivelyale this Yearly >>>"); // Log(WinHelper.cmd("ipconfig /all")); }