以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 无法正常解析公网IP地址时报错处理 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=194209) |
-- 作者:L88919138 -- 发布时间:2024/11/19 10:25:00 -- 无法正常解析公网IP地址时报错处理 下面代码能正常解析出公网IP地址时是不会报错,可一旦无法有效解析出公网IP地址时便会报错,测得是最后一行代码报错,该如何用判断语句来规避? Dim hc As New HttpClient("https://ip.51240.com/") \'无法有效解析出公网IP地址 \'Dim hc As New HttpClient("http://myip.ipip.net") \'可以正常解析出公网IP地址 Dim txt As String = hc.GetData() Dim pattern As String = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?) " Dim rgx = New System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase) Dim Matches As Object = rgx.Matches(txt) output.show(Matches.Item(0).Value) \'测得报错的代码 |
-- 作者:有点蓝 -- 发布时间:2024/11/19 10:40:00 -- Dim rgx = New System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase) Dim Matches As System.Text.RegularExpressions.MatchCollection = rgx.Matches(txt) If Matches.Count > 0 Then output.show(Matches.Item(0).Value) \'测得报错的代码 End If |
-- 作者:L88919138 -- 发布时间:2024/11/19 10:41:00 -- 谢谢大师指点 |