Har fundet et projekt på nettet som jeg har modificeret til dig. Du skal have 3 textboxe:
IPrStart er IpRangeStart i dit tilfælde 81.7.128.0 IPrSlut er IpRangeSlut i dit tilfælde 81.7.128.18
IpTjeck er Ip'en du vil tjekke i dit tilfælde 81.7.129.240
Og så skal du ha en command button: Command1
Here goes:
Option Explicit
Private Type TByteRec B(1 To 8) As Byte End Type
Private Type TCcyRec C As Currency End Type
Private Sub Command1_Click() Call LS_PrintRange(IPrStart.Text, IPrSlut.Text) End Sub
Private Sub LS_PrintRange(LoIP$, HiIP$) Dim LO As Currency, HI As Currency Dim l9 As Currency
LO = LF_IpToCcy(LoIP$) HI = LF_IpToCcy(HiIP$)
Debug.Print LF_CcyToIP(LO) Debug.Print LF_CcyToIP(HI) ' these numbers are fairly meaningless to a human Debug.Print LO Debug.Print HI Debug.Print ' --- Currency is an 8 Byte Integer / 10000 For l9 = LO To HI Step 0.0001
If LF_CcyToIP(l9) = IpTjeck.Text Then MsgBox "HURRA" End If
Debug.Print LF_CcyToIP(l9) Next
End Sub
Private Function LF_IpToCcy(ip$) As Currency Dim ByteRec As TByteRec Dim CcyRec As TCcyRec Dim l9&, q&, pos&
' Fill in the Low 4 bytes [4][3][2][1] ' Here one would use Split() in VB6 q = 1 For l9 = 1 To 4 pos = InStr(q, ip$, ".") If pos = 0 Then pos = Len(ip$) + 1 ByteRec.B(5 - l9) = Val(Mid$(ip$, q, pos - q)) q = pos + 1 Next ' --- LSet CcyRec = ByteRec LF_IpToCcy = CcyRec.C
End Function
Private Function LF_CcyToIP(No As Currency) As String Dim ByteRec As TByteRec Dim CcyRec As TCcyRec Dim l9&, S$
CcyRec.C = No LSet ByteRec = CcyRec
' --- Build 4.3.2.1 For l9 = 1 To 4 S$ = CStr(ByteRec.B(l9)) + S$ If l9 < 4 Then S$ = "." + S$ Next
Dim varIP As String varIP = "81.7.129.240" Dim ip4b() As Long ip4b = Split(varIP,".") Dim iplong As Long iplong = ip4b(0)*256*256*256 + ip4b(1)*256*256 + ip4b(2)*256 + ip4b(3)
If (iptjeklong>=iplong) AND (iptjeklong<=netlong) Then wscript.echo "IP " & iptjek & " er del af nettet " & ipstr & "/" & highbits Else wscript.echo "IP " & iptjek & " er IKKE del af nettet " & ipstr & "/" & highbits End If
Private Function StringToLong(addr As String) As Long Dim parts() As String parts = Split(addr, ".") StringToLong = CLng(parts(0)) * 256 * 256 * 256 + CLng(parts(1)) * 256 * 256 + CLng(parts(2)) * 256 + CLng(parts(3)) End Function
Private Sub Check_Click() Dim netval As Long netval = StringToLong(net.Text) Dim hostval As Long hostval = StringToLong(host.Text) Dim netsize As Integer netsize = 2 ^ (32 - CInt(size.Text)) If (netval <= hostval) And (hostval <= netval + netsize - 1) Then MsgBox "Same net" Else MsgBox "Different net" End If End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.