C#獲取本機(jī)IP
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
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 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |