查看: 2423|回復: 0
打印 上一主題 下一主題

IP計算(遞增)計算程式

[複製鏈接]
跳轉到指定樓層
1#
發表於 2007-7-27 20:53:17 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
'**************************************
' 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:
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

本論壇為非營利之網路平台,所有文章內容均為網友自行發表,不代表論壇立場!若涉及侵權、違法等情事,請告知版主處理。


Page Rank Check

廣告刊登  |   交換連結  |   贊助我們  |   服務條款  |   免責聲明  |   客服中心  |   中央分站

手機版|中央論壇

GMT+8, 2026-11-2 02:33 , Processed in 0.032724 second(s), 15 queries .

Powered by Discuz!

© 2005-2015 Copyrights. Set by YIDAS

快速回復 返回頂部 返回列表