Results 1 to 10 of 165

Thread: VPN Forum access and IP addresse Tests

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10




    Local Host address, Computer name
    There are a couple of Win32 APIs which will get this information.
    We just need to write a small amount of coding to get the function to do what we want and also a bit of manipulaation to give the information as we need it.
    For the computer name this is simply a function to give us a string.
    Code:
    Option Explicit
    Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, ByRef nSize As Long) As Long
    '  "GetComputerNameA" (ByVal lpBuffer As String, ByRef nSize As Long) As Long
    Function ComputerName() As String                                                                                                                                                                        ' GHB and sex..
    Dim NmeLen As Long, lngX As Long, strCompName As String
     Let NmeLen = 999: Let strCompName = "                                     "     ' variables must be initialised or API things often dont work                                                            ' String$(50, 0)
     Let lngX = GetComputerName(strCompName, NmeLen) '
        If lngX <> 0 Then ' returns 1 if it works
         Let ComputerName = strCompName '   Left$(strCompName, NmeLen)   ' The first argument variable gets like a LSet done on it
        Else
         Let ComputerName = "Couldn't get Computer name"
        End If
     Let ComputerName = Left$(ComputerName, NmeLen) ' We must do this as there is a  Chr(0)  after the name ....  Let ComputerName = Trim(ComputerName) ' this is no good, - it leaves Chr(0) on the end which means that ComputerName is the last thing that will get printed
     'Call WtchaGot(ComputerName)
    End Function
    




    The Win32 API for the local IP address is slightly more complicated. It will give us a table/ array of all the IP addresses held. The first is generally that we are interested in. it seems to be added when a VPN connection is made
    Code:
    Option Explicit
    Private Declare Function GetIpAddrTable_API Lib "IpHlpApi" Alias "GetIpAddrTable" (ByRef pIPAddrTable As Any, ByRef pdwSize As Long, ByVal bOrder As Long) As Long    '   http://www.source-code.biz/snippets/vbasic/8.htm
    '  "GetIpAddrTable" (ByRef pIPAddrTable As Any, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
    Public Function GetIpAddrTable() As String  '       Christian d'Heureuse, www.source-code.biz  http://www.source-code.biz/snippets/vbasic/8.htm
    Rem 1 We give the API function some info , and that seems to make it fill up an array with table values
    Dim Buf(0 To 1234) As Byte ' Buf(0 To 511) As Byte ' must be Byte or overflow at NrOfEntries
    Dim BufSize As Long: Let BufSize = 12345
    Dim rc As Long: Let rc = GetIpAddrTable_API(Buf(0), BufSize, 1)
       'If rc <> 0 Then Err.Raise vbObjectError, , "GetIpAddrTable failed with return value " & rc
    Dim NrOfEntries As Integer: NrOfEntries = Buf(1) * 256 + Buf(0)
       'If NrOfEntries = 0 Then GetIpAddrTable = Array(): Exit Function
    
    Dim i As Long
       For i = 0 To NrOfEntries - 1
        Dim j As Long, s As String
          For j = 0 To 3
          Dim Indcy As Long: Let Indcy = 4 + i * 24 + j
           s = s & IIf(j > 0, ".", "") & Buf(Indcy): Debug.Print Indcy & "   " & Buf(Indcy) ' This code line just builds the final string for each IP address, with a "." before all but the first of the 4 number parts  ---  for example like  192 . 168 . 2 . 110
          Next j
         Dim strIPs As String: Let strIPs = strIPs & "   " & s: Let s = ""
        Next
       GetIpAddrTable = strIPs: Debug.Print strIPs
    End Function
    
    '    4   127
    '    5   0
    '    6   0
    '    7   1
    '    28   192
    '    29   168
    '    30   2
    '    31   110
    '       127.0.0.1   192.168.2.110                                                                                          ' _
    
    '    4   10
    '    5   132
    '    6   13
    '    7   113
    '    28   127
    '    29   0
    '    30   0
    '    31   1
    '    52   192
    '    53   168
    '    54   2
    '    55   110
    '       10.132.13.113   127.0.0.1   192.168.2.110
    '     1  2  3    4   5   6  7      8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    '    25 26 27   28  29  30  31     32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    '    49 50 51   52  53  54  55
    '               10  132  13  127
    '               127  0   0   1
    '               192 168  2  110

    If we examine that coding above, and experiment with what it does, we see a couple of things:
    Rem 1
    _ It is doing a strange thing, as API's often do. That is to say the API works similarly to a normal VBA function, except the way each argument is a mystery.. following some set of rules/coding which probably the author wrote when he was drunk and no one can remember anymore.
    You must make an array of Byte types. The array should be fairly big.
    You must give the first array element and the size of the array to the API Function.
    Then magically the array gets filled. Presumably some internally held table is put into the array
    Rem 2
    A bit of maths is done to pick out the elements we want from the returned filled array

    The final analysis here of a typical output can be helpful to try and understand another way to get this information
    Code:
    '     1  2  3    4   5   6  7      8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
    '    25 26 27   28  29  30  31     32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    '    49 50 51   52  53  54  55
    '               10  132  13  127
    '               127  0   0   1
    '               192 168  2  110
    Or maybe not. I am not sure. I doubt many people are…



    Last edited by DocAElstein; 01-07-2020 at 02:50 AM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

Similar Threads

  1. Table Tests. And Thread Copy Tests No Reply needed
    By DocAElstein in forum Test Area
    Replies: 1
    Last Post: 11-20-2018, 01:11 PM
  2. Table Tests. And Thread Copy Tests No Reply needed
    By DocAElstein in forum Test Area
    Replies: 1
    Last Post: 11-20-2018, 01:11 PM
  3. New Forum Style
    By Admin in forum Public News
    Replies: 2
    Last Post: 05-16-2014, 11:34 AM
  4. Forum performances
    By Loser Who Got Kicked Where The Sun Don't Shine in forum Greetings and Inception
    Replies: 1
    Last Post: 01-03-2013, 07:50 PM
  5. Replies: 2
    Last Post: 09-08-2012, 10:50 PM

Posting Permissions

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