C#获取本机IP
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
public void GetIPAddress()
{ string resultIP = string.Empty; System.Net.IPAddress[] ips = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList; foreach (System.Net.IPAddress ip in ips) { if (IsCorrentIP(ip.ToString())) { resultIP = ip.ToString(); break; } } } private bool IsCorrentIP(string ip) { string pattrn = @"(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])"; if (System.Text.RegularExpressions.Regex.IsMatch(ip, pattrn)) { return true; } else { return false; } } 该文章在 2019/10/18 17:24:49 编辑过 |
关键字查询
相关文章
正在查询... |