Results 1 to 7 of 7

Thread: MY OWN IP ADDRESS ?????

  1. #1

    Thread Starter
    Lively Member Edilson's Avatar
    Join Date
    Aug 2000
    Location
    Orlando
    Posts
    81
    I need a code to know my own IP address. Is this possible ??

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    This method isn't 100% always acurate...but:
    Code:
    'Add a winsock control and a textbox, and add this code
    Text1.Text = Winsock1.LocalIP
    Hope that helps,
    D!m
    Dim

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Is there any particular reason it isn't 100% effective.
    Aside from the fact that you add the overhead of the control to your project, it's slick.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    if ur using a router,

    it will show an Internal IP:

    192.168.*.*

    Instead of your External IP:
    62.31.*.*

    The only "Real" way would be to go to a website, that gets your REAL IP, and then get it from its contents or something :shrugs:

    : Such as a PHP's
    PHP Code:
    <?php
    $remoteadd 
    GetEnv("Remote_Addr");
    echo 
    "$remoteadd";
    ?>

    U can get the contents from that then,,
    But u need a webserver to read it from ETC :@
    Would be more "Wise" then the "Winsock1".

    But, If their using a Proxy, it will return dat :\
    Wayne

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    If you are using a router, The IP given by the website would be the address of the router. The IP of the local computer IS 192.168....

    Z.

  6. #6
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    yeh, but im guessing that he mite want his "External" IP

    If it is internal IP Address's...

    : Looks for Code :

    Theres this API:


    Call it like:

    VB Code:
    1. Module1.Start


    In a module Called "Module1"

    VB Code:
    1. 'Created By Verburgh Peter.
    2. ' 07-23-2001
    3. ' [email][email protected][/email]
    4. '-------------------------------------
    5. 'With this small application , you can detect the IP's installed on your computer,
    6. 'including subnet mask , BroadcastAddr..
    7. '
    8. 'I've wrote this because i've a programm that uses the winsock control, but,
    9. 'if you have multiple ip's  installed on your pc , you could get by using the Listen
    10. ' method the wrong ip ...
    11. 'Because Winsock.Localip => detects the default ip installed on your PC ,
    12. ' and in most of the cases it could be the LAN (nic) not the WAN (nic)
    13. 'So then you have to use the Bind function ,to bind to your right ip..
    14. 'but how do you know & find that ip ?
    15. 'you can find it now by this appl.. it check's in the api.. IP Table..
    16. '******************************************************************
    17.  
    18.  
    19. Const MAX_IP = 6   'To make a buffer... i dont think you have more than 5 ip on your pc..
    20.  
    21. Type IPINFO
    22.      dwAddr As Long   ' IP address
    23.     dwIndex As Long '  interface index
    24.     dwMask As Long ' subnet mask
    25.     dwBCastAddr As Long ' broadcast address
    26.     dwReasmSize  As Long ' assembly size
    27.     unused1 As Integer ' not currently used
    28.     unused2 As Integer '; not currently used
    29. End Type
    30.  
    31. Type MIB_IPADDRTABLE
    32.     dEntrys As Long   'number of entries in the table
    33.     mIPInfo(MAX_IP) As IPINFO  'array of IP address entries
    34. End Type
    35.  
    36. Type IP_Array
    37.     mBuffer As MIB_IPADDRTABLE
    38.     BufferLen As Long
    39. End Type
    40.  
    41. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    42. Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
    43. Sub main()
    44. frmIPCheck.Show
    45. End Sub
    46.  
    47. 'converts a Long  to a string
    48. Public Function ConvertAddressToString(longAddr As Long) As String
    49.     Dim myByte(3) As Byte
    50.     Dim Cnt As Long
    51.     CopyMemory myByte(0), longAddr, 4
    52.     For Cnt = 0 To 3
    53.         ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."
    54.     Next Cnt
    55.     ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
    56. End Function
    57.  
    58. Public Sub Start()
    59. Dim Ret As Long, Tel As Long
    60. Dim bBytes() As Byte
    61. Dim Listing As MIB_IPADDRTABLE
    62. Dim StaredLine As String
    63. StaredLine = vbCrLf & "**********************************************************"
    64. frmIPCheck.txtIPCheck = ""
    65.  
    66. On Error GoTo END1
    67.     GetIpAddrTable ByVal 0&, Ret, True
    68.  
    69.     If Ret <= 0 Then Exit Sub
    70.     ReDim bBytes(0 To Ret - 1) As Byte
    71.     'retrieve the data
    72.     GetIpAddrTable bBytes(0), Ret, False
    73.      
    74.     'Get the first 4 bytes to get the entry's.. ip installed
    75.     CopyMemory Listing.dEntrys, bBytes(0), 4
    76.          
    77.          frmIPCheck.lblIPsFound = Listing.dEntrys & " IP addresses found on your PC!" & vbCrLf
    78.          
    79.          frmIPCheck.txtIPCheck = StaredLine & vbCrLf & vbCrLf
    80.     For Tel = 0 To Listing.dEntrys - 1
    81.         'Copy whole structure to Listing..
    82.        ' MsgBox bBytes(tel) & "."
    83.         CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
    84.          frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & "IP address: " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
    85.          frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & "IP Subnetmask: " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
    86.          frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & "BroadCast IP address: " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf
    87.          frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & StaredLine & vbCrLf & vbCrLf
    88.     Next
    89.  
    90. 'MsgBox ConvertAddressToString(Listing.mIPInfo(1).dwAddr)
    91.  
    92. Exit Sub
    93. END1:
    94. MsgBox "ERROR"
    95. End Sub
    Wayne

  7. #7
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    BTW::

    frmIPCheck.txtIPCheck

    This needs to be changed to:

    MYForm.MyTextBox

    Text box needs to be multi lined,,,

    Will return 6 IP Addresses//

    VB Code:
    1. frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & "IP address: " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
    2.          frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & "IP Subnetmask: " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
    3.          frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & "BroadCast IP address: " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf

    That will return IP | Subnet Mask | Broadcast Address

    VB Code:
    1. ' Change to this for just IP:
    2.          frmIPCheck.txtIPCheck = frmIPCheck.txtIPCheck & "IP address: " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf

    To add it to a combo box, Change to:

    VB Code:
    1. ' Change to this for just IP:
    2.          frmIPCheck.MyCombo.AddItem ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr)

    Its all really cool, but this only returns LOCAL ADDRESSES. (No WinSock or that needed,

    U Can return however many you need too as well ,

    VB Code:
    1. Const MAX_IP = 6

    Alter this to make it less or more...

    Wayne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width