private string IPandPort(string temp)
{
string ipandport = temp;
string[] strDetail = ipandport.Split(":".ToCharArray());
string iptemp = strDetail[0];
string porttemp = strDetail[1];
string[] ipDetail = iptemp.Split(".".ToCharArray());
string ip = "";
string port="";
for (int i = 0; i < ipDetail.Length; i++)
{
if (ipDetail[i].Length < 3)
{
if (ipDetail[i].Length == 0)
{
ipDetail[i] = "000";
}
else if (ipDetail[i].Length == 1)
{
ipDetail[i] = "00" + ipDetail[i];
}
else if (ipDetail[i].Length == 2)
{
ipDetail[i] = "0" + ipDetail[i];
}
}
}
ip = ipDetail[0] + "." + ipDetail[1] + "." + ipDetail[2] + "." + ipDetail[3];
if (porttemp.Length < 5)
{
if (porttemp.Length == 1)
{
port = "0000" + porttemp;
}
else if (porttemp.Length == 2)
{
port = "000" + porttemp;
}
else if (porttemp.Length == 3)
{
port = "00" + porttemp;
}
else if (porttemp.Length == 4)
{
port = "0" + porttemp;
}
}
else
{
port = porttemp;
}
string ipport=ip+port ;
return ipport ;
}
将IP+Port转换成标准格式***.***.***.***:*****
最新推荐文章于 2021-12-08 16:34:17 发布