遍历主机所有的IP地址放入组件ComboBox
private void Form1_Load(object sender, EventArgs e){/* combobox 组件 */iplist.Items.Add(\"请选择IP地址\");List<string> str = new List<string>();/* 得到本机名字 */string hostname = Dns.GetHostName();/* 会返回所有地址,包括IPv4和IPv6 */System.Net.IPAddress[] addressList = Dns.GetHostAddresses(hostname);/* 遍历本机所有的IP地址放入到槽中 */foreach (IPAddress ip in addressList){string _temp_ip = ip.MapToIPv4().ToString();string[] ipstr = _temp_ip.Split(\'.\');if (ipstr[0] == \"127\" || ipstr[0] == \"10\" || ipstr[0] == \"172\"){continue;}else{string temp = str.Where(s => s == _temp_ip).FirstOrDefault();if (temp == null){str.Add(_temp_ip);iplist.Items.Add(_temp_ip);}}}iplist.SelectedIndex = 0;}

爱站程序员基地
![(原创)[C#] 一步一步自定义拖拽(Drag&Drop)时的鼠标效果:(一)基本原理及基本实现-爱站程序员基地](https://aiznh.com/wp-content/uploads/2022/07/20220721231016-62d9dcd85c40b-220x150.gif)

