C# 生成IP段
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C# 生成IP段,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2353字,纯文字阅读大概需要4分钟。
内容图文
![C# 生成IP段](/upload/InfoBanner/zyjiaocheng/709/d18fb7c76b78432bb3e2236de0c0dfbb.jpg)
- 安装Ipnetwork模块
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using LukeSkywalker.IPNetwork; 7 8 namespace ip_cidr 9 { 10 class ip_cidr 11 { 12 /* 13 public static List<string> Get_ipAddr() 14 { 15 IPNetwork ipnetwork = IPNetwork.Parse("192.168.168.0/16"); 16 string sip = Convert.ToString(ipnetwork.FirstUsable); 17 string lip = Convert.ToString(ipnetwork.LastUsable); 18 List<string> list = Get_CIDR(sip, lip); 19 for (int i = 0; i < list.Count; i++) 20 { 21 Console.WriteLine("Ip: {0} ", list[i]); 22 } 23 } 24 */ 25 public static List<string> Get_CIDR(string startIP, string lastIp) 26 { 27 string sip = Convert.ToString(startIP); 28 string lip = Convert.ToString(lastIp); 29 uint iStartip = ipTint(sip); 30 uint iEndIp = ipTint(lip); 31 //StringBuilder ip_result = new StringBuilder(); 32 List<string> ip_result = new List<string>(); 33 if (iEndIp >= iStartip) 34 { 35 for (uint ip = iStartip; ip <= iEndIp; ip++) 36 { 37 ip_result.Add(intTip(ip)); 38 } 39 40 } 41 else 42 { 43 Console.WriteLine("error"); 44 } 45 return ip_result; 46 } 47 public static uint ipTint(string ipStr) 48 { 49 string[] ip = ipStr.Split('.'); 50 uint ipcode = 0xFFFFFF00 | byte.Parse(ip[3]); 51 ipcode = ipcode & 0xFFFF00FF | (uint.Parse(ip[2]) << 0x8); 52 ipcode = ipcode & 0xFF00FFFF | (uint.Parse(ip[1]) << 0xF); 53 ipcode = ipcode & 0x00FFFFFF | (uint.Parse(ip[0]) << 0x18); 54 return ipcode; 55 } 56 public static string intTip(uint ipcode) 57 { 58 byte a = (byte)((ipcode & 0xFF000000) >> 0x18); 59 byte b = (byte)((ipcode & 0x00FF0000) >> 0xF); 60 byte c = (byte)((ipcode & 0x0000FF00) >> 0x8); 61 byte d = (byte)(ipcode & 0x000000FF); 62 string ipStr = string.Format("{0}.{1}.{2}.{3}", a, b, c, d); 63 return ipStr; 64 } 65 } 66 }
内容总结
以上是互联网集市为您收集整理的C# 生成IP段全部内容,希望文章能够帮你解决C# 生成IP段所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】