📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SimCDIR
{
public partial class Form1 : Form
{
string ip;
int[,] mask = new int[3, 32] { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
int[,] ip_test = new int[3, 32] { { 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
int[] ip_get2 = new int[32];
int[,] JugdeResult = new int[3, 32];
int ip_part;
int Way;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string ip1, ip2, ip3, ip4;
string str = "";
int length;
Way = 0;
ip1 = P1.Text;
ip_part = Convert.ToInt32(ip1);
ip1 = Convert.ToString(ip_part, 2);
length = ip1.Length;
for (int i = 0; i < 8; i++)
{
if (i < 8 - length)
str = str.Insert(i, "0");
else
{
str = str.Insert(i, Convert.ToString(ip1[i - (8 - length)]));
}
}
ip1 = str;
str = "";
ip2 = P2.Text;
ip_part = Convert.ToInt32(ip2);
ip2 = Convert.ToString(ip_part, 2);
length = ip2.Length;
for (int i = 0; i < 8; i++)
{
if (i < 8 - length)
str = str.Insert(i, "0");
else
{
str = str.Insert(i, Convert.ToString(ip2[i - (8 - length)]));
}
}
ip2 = str;
str = "";
ip3 = P3.Text;
ip_part = Convert.ToInt32(ip3);
ip3 = Convert.ToString(ip_part, 2);
length = ip3.Length;
for (int i = 0; i < 8; i++)
{
if (i < 8 - length)
str = str.Insert(i, "0");
else
{
str = str.Insert(i, Convert.ToString(ip3[i - (8 - length)]));
}
}
ip3 = str;
str = "";
ip4 = P4.Text;
ip_part = Convert.ToInt32(ip4);
ip4 = Convert.ToString(ip_part, 2);
length = ip4.Length;
for (int i = 0; i < 8; i++)
{
if (i < 8 - length)
str = str.Insert(i, "0");
else
{
str = str.Insert(i, Convert.ToString(ip4[i - (8 - length)]));
}
}
ip4 = str;
str = ip1 + ip2 + ip3 + ip4;
for (int i = 0; i < 32; i++)
{
ip_get2[i] = Convert.ToInt32(str[i]);
ip_get2[i] = ip_get2[i] - 48;
}
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 32; j++)
{
JugdeResult[i, j] = (ip_get2[j]) & (mask[i, j]);
if (JugdeResult[i, j] != ip_test[i, j])
break;
else if (j == 31)
{
Way = i + 1;
tMessageWay.Text = Convert.ToString(Way);
}
}
}
if (Way == 0)
{
MessageBox.Show("该地址未进行过分配,转向默认路由!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -