以文本方式查看主题 - 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=162994) |
-- 作者:fvcfox -- 发布时间:2021/4/20 10:16:00 -- 有无判断网址是数字IP的网址方法 如题 |
-- 作者:有点蓝 -- 发布时间:2021/4/20 10:50:00 -- Dim url As String = "http://192.168.0.1:8080/123" Dim m As Integer = url.IndexOf("//") Dim n As Integer = url.IndexOf("/",m+2) Dim y As String If n > -1 Then y = url.SubString(m+2,n - m - 2) Else y = url.SubString(m+2) End If If y.Contains(":") Then y = y.Split(":")(0) Dim yr() As String = y.Split(".") If yr.Length <> 4 Then msgbox("不是IP") Return "" End If Dim a As Integer For i As Integer = 0 To yr.Length - 1 If Integer.TryParse(yr(i),a) AndAlso a < 0 OrElse a > 255 msgbox("不是IP") Return "" End If Next msgbox("是IP")
|