Results 1 to 19 of 19

Thread: ip address

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Ca
    Posts
    93

    Question

    How on your computer would you be able to find out your ip address?
    Timbudtwo
    I have no life, only one with computers.

    VB 6.0 Enterprise Edition
    [hr]

  2. #2
    Junior Member
    Join Date
    Jan 1999
    Location
    Juiz de Fora, MG, Brazil
    Posts
    30
    You have several kinds to know this.

    Why do you need to know about this?

    Are you on LAN?

    Emidio do Nascimento
    --------------------
    Programmer, teacher and consultant.
    [email protected]
    Juiz de Fora/MG
    BRAZIL

  3. #3
    Guest
    Or run the file - C:\WINDOWS\Winipcfg.exe.

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Unhappy

    Hm,I tried both and both return 10.1.0.67 which is my IP behind the proxy I think... is there a way to get the 'real' IP?

  5. #5
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    C:\WINDOWS\Winipcfg.exe will return your real ip even on a proxy server.

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Some of your other answers may give you this, but might as well say it anyway.
    Text1.text = Winsock1.LocalIP

  7. #7
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    Ok, are you dialing up or not... there is a big difference... if you aren't dialing up then the only ip you will ever have is your "fake"... but I presume that since you are using a proxy you aren't dialing up... there for you I think all you will ever get is the proxy address... which is one of the reasons some internet app's don't work behind a proxy.

  8. #8
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    text1.text = Winsock1.LocalIP
    won't give you your real ip on a proxy server, unless the winsock is connenected to something.

  9. #9
    Addicted Member Stick's Avatar
    Join Date
    Aug 1999
    Location
    Iowa
    Posts
    152
    text1.text = Winsock1.LocalIP
    won't give you your real ip on a proxy server, unless the winsock is connenected to something.
    ??

    It will give your IP but you need the winsock OCX added into you project You don't need to be connected to anything But It will return your "fake" ip (your poxy/lan ip)

  10. #10
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    stick if you have the winsock loaded into your project and you are on a normal dial up it will return your ip address, but if you are on a proxy server and the winsock is not actually connected to anything its just idle, it does not give you your real ip address, it gives you some bogus ip address. for example I am on a proxy server and for me it always returns 4.0.0.3
    which is not my ip address, but yet if the winsock control is actually connected to something it will give me my actual ip address.

  11. #11
    Addicted Member Stick's Avatar
    Join Date
    Aug 1999
    Location
    Iowa
    Posts
    152
    Yes i know that if you are on dial up it will give that,.

    But When I Use It it give me my Lan Ip Address
    Hmmm
    Wonder Why


    Any Way's Later

  12. #12
    Lively Member
    Join Date
    Apr 2000
    Posts
    110

    Question May work? Dunno, but worth a try...

    I understand what your saying, but try the following code. It will return your IP (but it may not be the real one). Just try it and see, I have used this on my school network which is on a LAN, and it seemed to work OK.

    Create a new Class file and name it "Net". Put the following code into it. BTW, this class also gives some other network / internet related functions. Just explore it.

    Code:
    'Net.cls
    Option Explicit
    
    Private Const INTERNET_CONNECTION_LAN As Long = &H2
    Private Const INTERNET_CONNECTION_MODEM As Long = &H1
    
    Private Const NCBASTAT = &H33
    Private Const NCBNAMSZ = 16
    Private Const HEAP_ZERO_MEMORY = &H8
    Private Const HEAP_GENERATE_EXCEPTIONS = &H4
    Private Const NCBRESET = &H32
    
    Private Const MAX_WSADescription = 256
    Private Const MAX_WSASYSStatus = 128
    Private Const ERROR_SUCCESS As Long = 0
    Private Const WS_VERSION_REQD As Long = &H101
    Private Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
    Private Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
    Private Const MIN_SOCKETS_REQD As Long = 1
    Private Const SOCKET_ERROR As Long = -1
    
    Private Type NCB
      ncb_command As Byte
      ncb_retcode As Byte
      ncb_lsn As Byte
      ncb_num As Byte
      ncb_buffer As Long
      ncb_length As Integer
      ncb_callname As String * NCBNAMSZ
      ncb_name As String * NCBNAMSZ
      ncb_rto As Byte
      ncb_sto As Byte
      ncb_post As Long
      ncb_lana_num As Byte
      ncb_cmd_cplt As Byte
      ncb_reserve(9) As Byte ' Reserved, must be 0
      ncb_event As Long
    End Type
    
    Private Type ADAPTER_STATUS
      adapter_address(5) As Byte
      rev_major As Byte
      reserved0 As Byte
      adapter_type As Byte
      rev_minor As Byte
      duration As Integer
      frmr_recv As Integer
      frmr_xmit As Integer
      iframe_recv_err As Integer
      xmit_aborts As Integer
      xmit_success As Long
      recv_success As Long
      iframe_xmit_err As Integer
      recv_buff_unavail As Integer
      t1_timeouts As Integer
      ti_timeouts As Integer
      Reserved1 As Long
      free_ncbs As Integer
      max_cfg_ncbs As Integer
      max_ncbs As Integer
      xmit_buf_unavail As Integer
      max_dgram_size As Integer
      pending_sess As Integer
      max_cfg_sess As Integer
      max_sess As Integer
      max_sess_pkt_size As Integer
      name_count As Integer
    End Type
    
    Private Type NAME_BUFFER
      name As String * NCBNAMSZ
      name_num As Integer
      name_flags As Integer
    End Type
    
    Private Type ASTAT
      adapt As ADAPTER_STATUS
      NameBuff(30) As NAME_BUFFER
    End Type
    
    Private Type HostEnt
       hName      As Long
       hAliases   As Long
       hAddrType  As Integer
       hLen       As Integer
       hAddrList  As Long
    End Type
    
    Private Type WSADATA
       wVersion      As Integer
       wHighVersion  As Integer
       szDescription(0 To MAX_WSADescription)   As Byte
       szSystemStatus(0 To MAX_WSASYSStatus)    As Byte
       wMaxSockets   As Integer
       wMaxUDPDG     As Integer
       dwVendorInfo  As Long
    End Type
    
    
    Private Declare Function InternetGetConnectedState _
    Lib "wininet.dll" (ByRef lpSFlags As Long, _
    ByVal dwReserved As Long) As Long
    
    Private Declare Function Netbios Lib "netapi32.dll" _
    (pncb As NCB) As Byte
    
    Private Declare Sub CopyMemory Lib "kernel32" _
    Alias "RtlMoveMemory" (hpvDest As Any, _
    ByVal hpvSource As Long, ByVal cbCopy As Long)
    
    Private Declare Function GetProcessHeap Lib "kernel32" _
    () As Long
    
    Private Declare Function HeapAlloc Lib "kernel32" _
    (ByVal hHeap As Long, ByVal dwFlags As Long, _
    ByVal dwBytes As Long) As Long
    
    Private Declare Function HeapFree Lib "kernel32" _
    (ByVal hHeap As Long, ByVal dwFlags As Long, _
    lpMem As Any) As Long
    
    Private Declare Function WSAGetLastError Lib "wsock32.dll" _
    () As Long
    
    Private Declare Function WSAStartup Lib "wsock32.dll" _
       (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long
       
    Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
    
    Private Declare Function gethostname Lib "wsock32.dll" _
       (ByVal szHost As String, ByVal dwHostLen As Long) As Long
       
    Private Declare Function gethostbyname Lib "wsock32.dll" _
       (ByVal szHost As String) As Long
    
    '~Function for retrieving the MAC or ethernet address
    ' from the networked machine. On error, the returned string
    ' will equal 8 zeros.
    Public Function GetEthernet() As String
    
        Dim udtNCB       As NCB
        Dim bytResponse  As Byte
        Dim udtASTAT     As ASTAT
        Dim udtTempASTAT As ASTAT
        Dim lngASTAT     As Long
        Dim strOut       As String
        Dim x            As Integer
    
            udtNCB.ncb_command = NCBRESET
            bytResponse = Netbios(udtNCB)
            udtNCB.ncb_command = NCBASTAT
            udtNCB.ncb_lana_num = 0
            udtNCB.ncb_callname = "* "
            udtNCB.ncb_length = Len(udtASTAT)
            lngASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, udtNCB.ncb_length)
            strOut = ""
      
        If lngASTAT Then
      
            udtNCB.ncb_buffer = lngASTAT
            bytResponse = Netbios(udtNCB)
            
            CopyMemory udtASTAT, udtNCB.ncb_buffer, Len(udtASTAT)
         
            With udtASTAT.adapt
                
                For x = 0 To 5
                    
                    strOut = strOut & Right$("00" & Hex$(.adapter_address(x)), 2)
                
                Next x
        
            End With
        
            HeapFree GetProcessHeap(), 0, lngASTAT
            
        End If
      
      GetEthernet = strOut
      
    End Function
    
    Public Function GetIPAddress() As String
    
       Dim sHostName    As String * 256
       Dim lpHost    As Long
       Dim Host      As HostEnt
       Dim dwIPAddr  As Long
       Dim tmpIPAddr() As Byte
       Dim i         As Integer
       Dim sIPAddr  As String
       
        If Not SocketsInitialize() Then
            GetIPAddress = ""
            Exit Function
        End If
       
        If gethostname(sHostName, 256) = SOCKET_ERROR Then
            GetIPAddress = ""
            'MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & _
            '      " has occurred. Unable to successfully get Host Name."
            SocketsCleanup
            Exit Function
        End If
       
            sHostName = Trim$(sHostName)
            lpHost = gethostbyname(sHostName)
        
        If lpHost = 0 Then
            GetIPAddress = ""
            'MsgBox "Windows Sockets are not responding. " & _
            '    "Unable to successfully get Host Name."
            SocketsCleanup
            Exit Function
        End If
       
       CopyMemory Host, lpHost, Len(Host)
       CopyMemory dwIPAddr, Host.hAddrList, 4
       
       ReDim tmpIPAddr(1 To Host.hLen)
       
       CopyMemory tmpIPAddr(1), dwIPAddr, Host.hLen
       
       For i = 1 To Host.hLen
          
          sIPAddr = sIPAddr & tmpIPAddr(i) & "."
       
       Next
       
       GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
       
       SocketsCleanup
        
    End Function
    Public Function GetIPHostName() As String
    
        Dim sHostName As String * 256
        
        If Not SocketsInitialize() Then
            GetIPHostName = ""
            Exit Function
        End If
        
        If gethostname(sHostName, 256) = SOCKET_ERROR Then
            GetIPHostName = "Error in retrieving IP host name!"
            Resume Next
            'MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & _
                    '" has occurred.  Unable to successfully get Host Name."
            SocketsCleanup
            Exit Function
        End If
        
        GetIPHostName = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
        SocketsCleanup
    
    End Function
    Private Function HiByte(ByVal wParam As Integer)
    
        HiByte = wParam \ &H100 And &HFF&
     
    End Function
    Private Function LoByte(ByVal wParam As Integer)
    
        LoByte = wParam And &HFF&
    
    End Function
    Private Sub SocketsCleanup()
    
        If WSACleanup() <> ERROR_SUCCESS Then
            Resume Next
        End If
        
    End Sub
    
    Private Function SocketsInitialize() As Boolean
    
       Dim WSAD As WSADATA
       Dim sLoByte As String
       Dim sHiByte As String
       
       If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
       '"The 32-bit Windows Socket is not responding."
          SocketsInitialize = False
          Exit Function
       End If
       
       
       If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
            'MsgBox "This application requires a minimum of " & _
                    CStr(MIN_SOCKETS_REQD) & " supported sockets."
            
            SocketsInitialize = False
            Exit Function
       End If
       
       
       If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or _
         (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And _
          HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
          
          sHiByte = CStr(HiByte(WSAD.wVersion))
          sLoByte = CStr(LoByte(WSAD.wVersion))
          
          'MsgBox "Sockets version " & sLoByte & "." & sHiByte & _
                ' " is not supported by 32-bit Windows Sockets."
          
          SocketsInitialize = False
          Exit Function
          
       End If
        SocketsInitialize = True
    End Function
    
    Property Get GetOnline() As Boolean
        GetOnline = InternetGetConnectedState(0&, 0&)
    End Property
    
    Property Get GetStateOnline() As String
    If GetOnline Then
        GetStateOnline = "Active."
    Else
        GetStateOnline = "Inactive."
    End If
    End Property
    
    Public Function ViaLAN() As Boolean
    
    Dim SFlags As Long
    'return the flags associated with the connection
    Call InternetGetConnectedState(SFlags, 0&)
    
    'True if the Sflags has a LAN connection
    ViaLAN = SFlags And INTERNET_CONNECTION_LAN
    
    End Function
    
    Public Function ViaModem() As Boolean
    
    Dim SFlags As Long
    'return the flags associated with the connection
    Call InternetGetConnectedState(SFlags, 0&)
    
    'True if the Sflags has a modem connection
    ViaModem = SFlags And INTERNET_CONNECTION_MODEM
    
    End Function
    Now, in a form, or a module.

    Code:
    Dim netCls As New Net
    
    'To get the local IP, call this. It returns a string containing the IP of your machine.
    Msgbox netCls.GetIPAddress
    Hope this helps in some way...

    Laterz

    REM

  13. #13
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Nope, everything just returns the fake IP... Oh and WinSock even returns the faked IP when it's not connected

    However, I looked at ICQ and it gives me a different IP, 194.209.172.146, which may be true but people can't connect to this address (ie. when I'm running a Winsock project).

    Also I made a li'll WinSock project and connected to a friend with dialup, he sent me local- and remoteip and I sent both too, his remoteIP was my fake and my localIP was the one above.

    I think now this IS my IP, but no one can connect to it when I'm running a project... well, at least I can connect to the others...

  14. #14
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: May work? Dunno, but worth a try...

    Quote Originally Posted by REM View Post
    Code:
    'Net.cls
    Option Explicit
    
    Private Const INTERNET_CONNECTION_LAN As Long = &H2
    Private Const INTERNET_CONNECTION_MODEM As Long = &H1
    
    Private Const NCBASTAT = &H33
    Private Const NCBNAMSZ = 16
    Private Const HEAP_ZERO_MEMORY = &H8
    Private Const HEAP_GENERATE_EXCEPTIONS = &H4
    Private Const NCBRESET = &H32
    
    Private Const MAX_WSADescription = 256
    Private Const MAX_WSASYSStatus = 128
    Private Const ERROR_SUCCESS As Long = 0
    Private Const WS_VERSION_REQD As Long = &H101
    Private Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
    Private Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&
    Private Const MIN_SOCKETS_REQD As Long = 1
    Private Const SOCKET_ERROR As Long = -1
    
    Private Type NCB
      ncb_command As Byte
      ncb_retcode As Byte
      ncb_lsn As Byte
      ncb_num As Byte
      ncb_buffer As Long
      ncb_length As Integer
      ncb_callname As String * NCBNAMSZ
      ncb_name As String * NCBNAMSZ
      ncb_rto As Byte
      ncb_sto As Byte
      ncb_post As Long
      ncb_lana_num As Byte
      ncb_cmd_cplt As Byte
      ncb_reserve(9) As Byte ' Reserved, must be 0
      ncb_event As Long
    End Type
    
    Private Type ADAPTER_STATUS
      adapter_address(5) As Byte
      rev_major As Byte
      reserved0 As Byte
      adapter_type As Byte
      rev_minor As Byte
      duration As Integer
      frmr_recv As Integer
      frmr_xmit As Integer
      iframe_recv_err As Integer
      xmit_aborts As Integer
      xmit_success As Long
      recv_success As Long
      iframe_xmit_err As Integer
      recv_buff_unavail As Integer
      t1_timeouts As Integer
      ti_timeouts As Integer
      Reserved1 As Long
      free_ncbs As Integer
      max_cfg_ncbs As Integer
      max_ncbs As Integer
      xmit_buf_unavail As Integer
      max_dgram_size As Integer
      pending_sess As Integer
      max_cfg_sess As Integer
      max_sess As Integer
      max_sess_pkt_size As Integer
      name_count As Integer
    End Type
    
    Private Type NAME_BUFFER
      name As String * NCBNAMSZ
      name_num As Integer
      name_flags As Integer
    End Type
    
    Private Type ASTAT
      adapt As ADAPTER_STATUS
      NameBuff(30) As NAME_BUFFER
    End Type
    
    Private Type HostEnt
       hName      As Long
       hAliases   As Long
       hAddrType  As Integer
       hLen       As Integer
       hAddrList  As Long
    End Type
    
    Private Type WSADATA
       wVersion      As Integer
       wHighVersion  As Integer
       szDescription(0 To MAX_WSADescription)   As Byte
       szSystemStatus(0 To MAX_WSASYSStatus)    As Byte
       wMaxSockets   As Integer
       wMaxUDPDG     As Integer
       dwVendorInfo  As Long
    End Type
    
    
    Private Declare Function InternetGetConnectedState _
    Lib "wininet.dll" (ByRef lpSFlags As Long, _
    ByVal dwReserved As Long) As Long
    
    Private Declare Function Netbios Lib "netapi32.dll" _
    (pncb As NCB) As Byte
    
    Private Declare Sub CopyMemory Lib "kernel32" _
    Alias "RtlMoveMemory" (hpvDest As Any, _
    ByVal hpvSource As Long, ByVal cbCopy As Long)
    
    Private Declare Function GetProcessHeap Lib "kernel32" _
    () As Long
    
    Private Declare Function HeapAlloc Lib "kernel32" _
    (ByVal hHeap As Long, ByVal dwFlags As Long, _
    ByVal dwBytes As Long) As Long
    
    Private Declare Function HeapFree Lib "kernel32" _
    (ByVal hHeap As Long, ByVal dwFlags As Long, _
    lpMem As Any) As Long
    
    Private Declare Function WSAGetLastError Lib "wsock32.dll" _
    () As Long
    
    Private Declare Function WSAStartup Lib "wsock32.dll" _
       (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long
       
    Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
    
    Private Declare Function gethostname Lib "wsock32.dll" _
       (ByVal szHost As String, ByVal dwHostLen As Long) As Long
       
    Private Declare Function gethostbyname Lib "wsock32.dll" _
       (ByVal szHost As String) As Long
    
    '~Function for retrieving the MAC or ethernet address
    ' from the networked machine. On error, the returned string
    ' will equal 8 zeros.
    Public Function GetEthernet() As String
    
        Dim udtNCB       As NCB
        Dim bytResponse  As Byte
        Dim udtASTAT     As ASTAT
        Dim udtTempASTAT As ASTAT
        Dim lngASTAT     As Long
        Dim strOut       As String
        Dim x            As Integer
    
            udtNCB.ncb_command = NCBRESET
            bytResponse = Netbios(udtNCB)
            udtNCB.ncb_command = NCBASTAT
            udtNCB.ncb_lana_num = 0
            udtNCB.ncb_callname = "* "
            udtNCB.ncb_length = Len(udtASTAT)
            lngASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, udtNCB.ncb_length)
            strOut = ""
      
        If lngASTAT Then
      
            udtNCB.ncb_buffer = lngASTAT
            bytResponse = Netbios(udtNCB)
            
            CopyMemory udtASTAT, udtNCB.ncb_buffer, Len(udtASTAT)
         
            With udtASTAT.adapt
                
                For x = 0 To 5
                    
                    strOut = strOut & Right$("00" & Hex$(.adapter_address(x)), 2)
                
                Next x
        
            End With
        
            HeapFree GetProcessHeap(), 0, lngASTAT
            
        End If
      
      GetEthernet = strOut
      
    End Function
    
    Public Function GetIPAddress() As String
    
       Dim sHostName    As String * 256
       Dim lpHost    As Long
       Dim Host      As HostEnt
       Dim dwIPAddr  As Long
       Dim tmpIPAddr() As Byte
       Dim i         As Integer
       Dim sIPAddr  As String
       
        If Not SocketsInitialize() Then
            GetIPAddress = ""
            Exit Function
        End If
       
        If gethostname(sHostName, 256) = SOCKET_ERROR Then
            GetIPAddress = ""
            'MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & _
            '      " has occurred. Unable to successfully get Host Name."
            SocketsCleanup
            Exit Function
        End If
       
            sHostName = Trim$(sHostName)
            lpHost = gethostbyname(sHostName)
        
        If lpHost = 0 Then
            GetIPAddress = ""
            'MsgBox "Windows Sockets are not responding. " & _
            '    "Unable to successfully get Host Name."
            SocketsCleanup
            Exit Function
        End If
       
       CopyMemory Host, lpHost, Len(Host)
       CopyMemory dwIPAddr, Host.hAddrList, 4
       
       ReDim tmpIPAddr(1 To Host.hLen)
       
       CopyMemory tmpIPAddr(1), dwIPAddr, Host.hLen
       
       For i = 1 To Host.hLen
          
          sIPAddr = sIPAddr & tmpIPAddr(i) & "."
       
       Next
       
       GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1)
       
       SocketsCleanup
        
    End Function
    Public Function GetIPHostName() As String
    
        Dim sHostName As String * 256
        
        If Not SocketsInitialize() Then
            GetIPHostName = ""
            Exit Function
        End If
        
        If gethostname(sHostName, 256) = SOCKET_ERROR Then
            GetIPHostName = "Error in retrieving IP host name!"
            Resume Next
            'MsgBox "Windows Sockets error " & Str$(WSAGetLastError()) & _
                    '" has occurred.  Unable to successfully get Host Name."
            SocketsCleanup
            Exit Function
        End If
        
        GetIPHostName = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
        SocketsCleanup
    
    End Function
    Private Function HiByte(ByVal wParam As Integer)
    
        HiByte = wParam \ &H100 And &HFF&
     
    End Function
    Private Function LoByte(ByVal wParam As Integer)
    
        LoByte = wParam And &HFF&
    
    End Function
    Private Sub SocketsCleanup()
    
        If WSACleanup() <> ERROR_SUCCESS Then
            Resume Next
        End If
        
    End Sub
    
    Private Function SocketsInitialize() As Boolean
    
       Dim WSAD As WSADATA
       Dim sLoByte As String
       Dim sHiByte As String
       
       If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
       '"The 32-bit Windows Socket is not responding."
          SocketsInitialize = False
          Exit Function
       End If
       
       
       If WSAD.wMaxSockets < MIN_SOCKETS_REQD Then
            'MsgBox "This application requires a minimum of " & _
                    CStr(MIN_SOCKETS_REQD) & " supported sockets."
            
            SocketsInitialize = False
            Exit Function
       End If
       
       
       If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or _
         (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And _
          HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
          
          sHiByte = CStr(HiByte(WSAD.wVersion))
          sLoByte = CStr(LoByte(WSAD.wVersion))
          
          'MsgBox "Sockets version " & sLoByte & "." & sHiByte & _
                ' " is not supported by 32-bit Windows Sockets."
          
          SocketsInitialize = False
          Exit Function
          
       End If
        SocketsInitialize = True
    End Function
    
    Property Get GetOnline() As Boolean
        GetOnline = InternetGetConnectedState(0&, 0&)
    End Property
    
    Property Get GetStateOnline() As String
    If GetOnline Then
        GetStateOnline = "Active."
    Else
        GetStateOnline = "Inactive."
    End If
    End Property
    
    Public Function ViaLAN() As Boolean
    
    Dim SFlags As Long
    'return the flags associated with the connection
    Call InternetGetConnectedState(SFlags, 0&)
    
    'True if the Sflags has a LAN connection
    ViaLAN = SFlags And INTERNET_CONNECTION_LAN
    
    End Function
    
    Public Function ViaModem() As Boolean
    
    Dim SFlags As Long
    'return the flags associated with the connection
    Call InternetGetConnectedState(SFlags, 0&)
    
    'True if the Sflags has a modem connection
    ViaModem = SFlags And INTERNET_CONNECTION_MODEM
    
    End Function
    Now, in a form, or a module.

    Code:
    Dim netCls As New Net
    
    'To get the local IP, call this. It returns a string containing the IP of your machine.
    Msgbox netCls.GetIPAddress
    Hope this helps in some way...

    Laterz

    REM
    It seems "As Any" works OK on Window XP (Pentium 4),but crashed on Win7 (Win7 Professinal,Core i5). It is related Windows version or CPU?

    I got crash by running this code and some others by declaring HeapFree "lpMem As Any",I Suggest declaring HeapFree "Byval lpMem As Long":

    Code:
    Dim netCls As New Net
    
    debug.print netCls.GetEthernet

  15. #15
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: ip address

    Really? An 11 year old thread?

  16. #16
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: ip address

    Quote Originally Posted by baja_yu View Post
    Really? An 11 year old thread?
    I come cross this post because I am searching HeapFree API in VBForum.

  17. #17
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: ip address

    Just because you came across it doesn't mean you need to reply to it. Eleven years... The OP hasn't visited the forum in 9 years.

  18. #18
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: ip address

    Quote Originally Posted by baja_yu View Post
    Just because you came across it doesn't mean you need to reply to it. Eleven years... The OP hasn't visited the forum in 9 years.
    I have the responsibility to indicate the potential problem which I knew to give others alerting. And,thanks for other participators

  19. #19
    Addicted Member
    Join Date
    Jul 2009
    Posts
    150

    Re: ip address

    Make A new Form Add 3 Textbox Call Them LocalIPAddress, other one called ComputerNameBox, and one called ISPIPAddress then add following code
    Code:
    Imports System.Net
    Imports System.IO
    Imports System.Text.RegularExpressions
    
    
    Public Class Form1
    Declare Function SendARP Lib "iphlpapi.dll" Alias "SendARP" (ByVal DestIP As Int32, ByVal SrcIP As Int32, ByVal pMacAddr() As Byte, ByRef PhyAddrLen As Int32) As Int32
    declare that then add this code
    Code:
        Private Sub Network_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            GetIPAddress()
            InternetProtocolIPAddress()
        End Sub
        Private Sub InternetProtocolIPAddress()
            Dim req As HttpWebRequest = WebRequest.Create("http://whatismyip.com/automation/n09230945.asp")
            Dim res As HttpWebResponse = req.GetResponse()
            Dim Stream As Stream = res.GetResponseStream()
            Dim sr As StreamReader = New StreamReader(Stream)
            ISPIPAddress.Text = (sr.ReadToEnd())
        End Sub
    
    
        Private Sub GetIPAddress()
            On Error Resume Next
            Dim strHostName As String
            Dim strIPAddress As String
    
            strHostName = System.Net.Dns.GetHostName()
    
            strIPAddress = System.Net.Dns.Resolve(strHostName).AddressList(0).ToString()
    
            LocalIPAddress.Text = strIPAddress
            ComputerNameBox.Text = strHostName
        End Sub
    Last edited by pillhead2007; Mar 3rd, 2011 at 07:01 AM.

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