SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void WriteRegKey(string keyName, string ipm1, string ipm2, string p1, string p2)
  2. {
  3.     string value1 = p1; // Преобразование string в int
  4.     short i1 = Convert.ToInt16(value1);
  5.     int valueHex1 = IPAddress.NetworkToHostOrder(i1);
  6.     string h1 = valueHex1.ToString("X2");
  7.  
  8.     string value2 = p2; // Преобразование string в int
  9.     short i2 = Convert.ToInt16(value2);
  10.     int valueHex2 = IPAddress.NetworkToHostOrder(i2);
  11.     string h2 = valueHex2.ToString("X2");
  12.  
  13.     string str1 = ipm1;
  14.     var result1 = str1.Split('/');
  15.  
  16.     string input1 = result1[0];
  17.     string hex3 = string.Concat(input1.Split('.').Select(x => int.Parse(x).ToString("X2").PadLeft(2, '0')));
  18.            
  19.     int cidr1 = int.Parse(result1[1]);
  20.     BitVector32 bits1 = new BitVector32(-1 << (32 - cidr1));
  21.     string hex4 = bits1.Data.ToString("X2");
  22.  
  23.     string str2 = ipm2;
  24.     var result2 = str2.Split('/');
  25.  
  26.     string input3 = result2[0];
  27.     string hex5 = string.Concat(input3.Split('.').Select(x => int.Parse(x).ToString("X2").PadLeft(2, '0')));
  28.  
  29.     int cidr2 = int.Parse(result2[1]);
  30.     BitVector32 bits2 = new BitVector32(-1 << (32 - cidr2));
  31.     string hex6 = bits2.Data.ToString("X2");
  32.            
  33.  
  34.     // Преобразование в IP
  35.     var bytes = BitConverter.GetBytes((uint)bits1.Data);
  36.     IPAddress netMask = new IPAddress(bytes.Reverse().ToArray());
  37.  
  38.  
  39.     var IP1 = hex3; // Адрес 8.8.8.8
  40.     var IPm1 = hex4; // Маска 255.255.255.255
  41.     var IP2 = hex5; // Адрес2 9.9.9.9
  42.     var IPm2 = hex6; // Маска 255.255.255.255
  43.     var Type = "06"; // Тип протокола (6) он же TCP
  44.     var Port1 = h1; // Порт 1111
  45.     var Port2 = h2; // Порт 2222
  46.  
  47.     var guidText = (Guid.NewGuid().ToString("B"));
  48.     RegistryKey lm = Registry.LocalMachine;
  49.     RegistryKey cs1 = lm.CreateSubKey("SOFTWARE\\002");
  50.     RegistryKey cs2 = cs1.CreateSubKey("ipsecFilter" + guidText);
  51.     var hex2 = "B520DC80C82ED111A89E00A0248D30214600000001000000020000000000020000000000020000000000424899DBF729" +
  52.                "3E4B90A44D6BB8ACCB3001000000" + IP1 + IPm1 + IP2 + IPm2 + "00000000" + Type + "0000000000" + Port1 + Port2 + "00000000";
  53.     var valueReg = StringToByteArray(hex2);
  54.     cs2.SetValue("className", "ipsecFilter");
  55.     cs2.SetValue(keyName, valueReg, RegistryValueKind.Binary);
  56.     cs2.SetValue("ipsecDataType", "100", RegistryValueKind.DWord);
  57.     cs2.SetValue("ipsecID", guidText);
  58.     cs2.SetValue("ipsecName", "Белый список");
  59.     cs2.SetValue("name", "ipsecFilter" + guidText);
  60.     cs2.SetValue("whenChanged", "00000000", RegistryValueKind.DWord);
  61.     // Сохранение ключа и его значения в config.ini (value имя ключа || guidText имя раздела)
  62.     //ini.Write("ipsecFilter" + guidText, ip1 + "/" + ipm1, "IPsec");
  63.     ini.Write("ipsecFilter" + guidText, ipm1, "IPsec");
  64.  
  65.     textBoxHex.Text = hex2;
  66. }
  67. private void buttonHex_Click(object sender, EventArgs e)
  68. {
  69.     WriteRegKey("ipsecData", textBoxIPm1.Text, textBoxIPm2.Text, textBoxPort1.Text, textBoxPort2.Text);
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top