首页 > 代码库 > C# 指定ip段生成ip地址
C# 指定ip段生成ip地址
private void button1_Click(object sender, EventArgs e) { string StartIp = ""; string EndIp = ""; StartIp = Startinput.Text; EndIp = Endinput.Text; uint iStartip = ipTint(StartIp); uint iEndIp = ipTint(EndIp); //string ip_result=""; StringBuilder ip_result=new StringBuilder(); if (iEndIp >= iStartip) { for (uint ip = iStartip; ip <= iEndIp; ip++) { ip_result.Append(intTip(ip)).Append("\r\n"); //ip_result = ip_result + intTip(ip)+"\r\n"; } resultTextBox.Text = ip_result.ToString(); //RichTextBox } else { MessageBox.Show("天啊,起始ip居然比终止ip还大"); } } public static uint ipTint(string ipStr) { string[] ip = ipStr.Split(‘.‘); uint ipcode = 0xFFFFFF00 | byte.Parse(ip[3]); ipcode = ipcode & 0xFFFF00FF | (uint.Parse(ip[2]) << 0x8); ipcode = ipcode & 0xFF00FFFF | (uint.Parse(ip[1]) << 0xF); ipcode = ipcode & 0x00FFFFFF | (uint.Parse(ip[0]) << 0x18); return ipcode; } public static string intTip(uint ipcode) { byte a = (byte)((ipcode & 0xFF000000) >> 0x18); byte b = (byte)((ipcode & 0x00FF0000) >> 0xF); byte c = (byte)((ipcode & 0x0000FF00) >> 0x8); byte d = (byte)(ipcode & 0x000000FF); string ipStr = string.Format("{0}.{1}.{2}.{3}", a, b, c, d); return ipStr; }
C# 指定ip段生成ip地址
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。