中央論壇 - CENTER BBS

標題: IP計算(遞增)計算程式 [打印本頁]

作者: f66666602    時間: 2007-7-27 20:53
標題: IP計算(遞增)計算程式
'**************************************
' Name: Add One to an IP Address. 127.0.
'     0.1 --> 127.0.0.2
' Description:This function will take an
'     IP address and add 1 to it. Say you send
'     127.0.0.1, it will return 127.0.0.2. Its
'     nice because if one of the ranges has a
'     255 in it (the biggest number an IP rang
'     e can have) it will automatically add 1
'     to the next range and make the origonal
'     one back to 0 again. i guess it could be
'     good for an ip range scanner or somthing
'     .
' By: Steve Sellers
'
' Inputs:you call it by putting AddOne("
'     127.0.0.1") where 127.0.0.1 is the IP yo
'     u want to add 1 to.
'
' Returns:The function AddOne returns a
'     string, so u need a variable or controll
'     to recieve the returned value. (string)
'
' Assumes:text1 = AddOne("127.0.0.1")
'
' Side Effects:if you try and add one to
'     a ip that isnt real if will give u error
'     s
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=46824&lngWId=1'for details.'**************************************

Public Function AddOne(IP As String) As String
    Dim A As Long, B As Long, C As Long, D As Long
    Dim A1 As Long, B1 As Long, C1 As Long
    A1 = InStr(1, IP, ".")
    A = Mid(IP, 1, A1)
    IP = Mid(IP, A1 + 1, Len(IP) - A1)
    B1 = InStr(1, IP, ".")
    B = Mid(IP, 1, B1)
    IP = Mid(IP, B1 + 1, Len(IP) - B1)
    C1 = InStr(1, IP, ".")
    C = Mid(IP, 1, C1)
    IP = Mid(IP, C1 + 1, Len(IP) - C1)
    D = IP

    If D >= 255 Then

        If C >= 255 Then

            If B >= 255 Then

                If A >= 255 Then
                    'MsgBox "Unreal IP address"
                Else
                    A = A + 1
                End If
                B = 0
            Else
                B = B + 1
            End If
            C = 0
        Else
            C = C + 1
        End If
        D = 0
    Else
        D = D + 1
    End If
    AddOne = A & "." & B & "." & C & "." & D
End Function


Other 1 submission(s) by this author


Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
Your Vote!
What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor
See Voting Log
Other User Comments
7/11/2003 7:08:50 PM:Steve Sellers
Im awsome
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

7/11/2003 8:16:24 PM:Coding Genius
you can split them into their seperate
parts much easier. Example:
A =
Split(TheIP,''.'')(0)
B =
Split(TheIP,''.'')(1)
-or-
Arr =
Split(TheIP,''.'')
A = Arr(0)
B =
Arr(1)
Also, the very last line can
be coded cleaner with the JOIN function.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:




歡迎光臨 中央論壇 - CENTER BBS (https://mail.centerbbs.com/) Powered by Discuz! X3