Results 1 to 5 of 5

Thread: Ip

  1. #1

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    Arrow Ip

    is there any code which will print the users I.P on the screen?

  2. #2
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775

    ip

    MsgBox Winsock1.LocalIP
    Try This it might work for you

    Hope this helps

  3. #3

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    this didnt work, it said it needed a variable

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    VB Code:
    1. Option Explicit
    2. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    3. ' Copyright ©1996-2001 VBnet, Randy Birch, All Rights Reserved.
    4. ' Some pages may also contain other copyrights by the author.
    5. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    6. ' You are free to use this code within your own applications,
    7. ' but you are expressly forbidden from selling or otherwise
    8. ' distributing this source code without prior written consent.
    9. ' This includes both posting free demo projects made from this
    10. ' code as well as reproducing the code in text or html format.
    11. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    12.  
    13. Private Const MAX_ADAPTER_NAME_LENGTH         As Long = 256
    14. Private Const MAX_ADAPTER_DESCRIPTION_LENGTH  As Long = 128
    15. Private Const MAX_ADAPTER_ADDRESS_LENGTH      As Long = 8
    16. Private Const ERROR_SUCCESS  As Long = 0
    17.  
    18. Private Type IP_ADDRESS_STRING
    19.     IpAddr(0 To 15)  As Byte
    20. End Type
    21.  
    22. Private Type IP_MASK_STRING
    23.     IpMask(0 To 15)  As Byte
    24. End Type
    25.  
    26. Private Type IP_ADDR_STRING
    27.     dwNext     As Long
    28.     IpAddress  As IP_ADDRESS_STRING
    29.     IpMask     As IP_MASK_STRING
    30.     dwContext  As Long
    31. End Type
    32.  
    33. Private Type IP_ADAPTER_INFO
    34.   dwNext                As Long
    35.   ComboIndex            As Long  'reserved
    36.   sAdapterName(0 To (MAX_ADAPTER_NAME_LENGTH + 3))        As Byte
    37.   sDescription(0 To (MAX_ADAPTER_DESCRIPTION_LENGTH + 3)) As Byte
    38.   dwAddressLength       As Long
    39.   sIPAddress(0 To (MAX_ADAPTER_ADDRESS_LENGTH - 1))       As Byte
    40.   dwIndex               As Long
    41.   uType                 As Long
    42.   uDhcpEnabled          As Long
    43.   CurrentIpAddress      As Long
    44.   IpAddressList         As IP_ADDR_STRING
    45.   GatewayList           As IP_ADDR_STRING
    46.   DhcpServer            As IP_ADDR_STRING
    47.   bHaveWins             As Long
    48.   PrimaryWinsServer     As IP_ADDR_STRING
    49.   SecondaryWinsServer   As IP_ADDR_STRING
    50.   LeaseObtained         As Long
    51.   LeaseExpires          As Long
    52. End Type
    53.  
    54. Private Declare Function GetAdaptersInfo Lib "iphlpapi.dll" _
    55.   (pTcpTable As Any, _
    56.    pdwSize As Long) As Long
    57.    
    58. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    59.   (dst As Any, _
    60.    src As Any, _
    61.    ByVal bcount As Long)
    62.    
    63. Public Function LocalIPAddresses(ByVal sDelim As String) As String
    64.    
    65.   'api vars
    66.    Dim cbRequired  As Long
    67.    Dim buff()      As Byte
    68.    Dim Adapter     As IP_ADAPTER_INFO
    69.    Dim AdapterStr  As IP_ADDR_STRING
    70.    
    71.   'working vars
    72.    Dim ptr1        As Long
    73.    Dim sIPAddr     As String
    74.    Dim sAllAddr    As String
    75.    
    76.    Call GetAdaptersInfo(ByVal 0&, cbRequired)
    77.  
    78.    If cbRequired > 0 Then
    79.    
    80.       ReDim buff(0 To cbRequired - 1) As Byte
    81.      
    82.       If GetAdaptersInfo(buff(0), cbRequired) = ERROR_SUCCESS Then
    83.      
    84.         'get a pointer to the data stored in buff()
    85.          ptr1 = VarPtr(buff(0))
    86.                  
    87.         'ptr1 is 0 when no more adapters
    88.          Do While (ptr1 <> 0)
    89.          
    90.            'copy the data from the pointer to the
    91.            'first adapter into the IP_ADAPTER_INFO type
    92.             CopyMemory Adapter, ByVal ptr1, LenB(Adapter)
    93.          
    94.             With Adapter
    95.          
    96.               'the DHCP IP address is in the
    97.               'IpAddress.IpAddr member
    98.                sIPAddr = TrimNull(StrConv(.IpAddressList.IpAddress.IpAddr, vbUnicode))
    99.                sAllAddr = sAllAddr & sIPAddr & "+"
    100.                
    101.               'more?
    102.                ptr1 = .dwNext
    103.                
    104.             End With  'With Adapter
    105.            
    106.          Loop  'Do While (ptr1 <> 0)
    107.  
    108.       End If  'If GetAdaptersInfo
    109.    End If  'If cbRequired > 0
    110.  
    111.   'remove the last comma
    112.    If Len(sAllAddr) > 0 Then
    113.       sAllAddr = Left$(sAllAddr, Len(sAllAddr) - 1)
    114.    End If
    115.          
    116.   'return any string found
    117.    LocalIPAddresses = sAllAddr
    118.    
    119.    
    120. End Function
    121.  
    122.  
    123. Private Function TrimNull(item As String)
    124.  
    125.     Dim pos As Integer
    126.    
    127.    'double check that there is a chr$(0) in the string
    128.     pos = InStr(item, Chr$(0))
    129.     If pos Then
    130.           TrimNull = Left$(item, pos - 1)
    131.     Else: TrimNull = item
    132.     End If
    133.  
    134. End Function

    That's the needed code. Here's an usage example:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim sIP As String
    3.     Dim IP() As String
    4.     Dim i As Integer
    5.    
    6.     sIP = LocalIPAddresses("+")
    7.     IP = Split(sIP, "+")
    8.  
    9.     For i = 0 To UBound(IP)
    10.         MsgBox IP(i)
    11.     Next i
    12.    
    13. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775

    IP address

    This can also be achieved by adding a winsock control to your form and putting in this code:



    visual basic code:--------------------------------------------------------------------------------Private Sub Form_Load()

    MsgBox = Winsock1.LocalIP

    End Sub

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