[AccessD] External IP Address of Local Machine

MartyConnelly martyconnelly at shaw.ca
Thu Sep 16 12:53:53 CDT 2004


I am just curious as to what this WMI code would return working  through 
a router
I get something like this without one. I have garbled numbers.

DHCPEnabled: True
DHCPLeaseExpires: 13/09/2004 5:42:44 AM
DHCPLeaseObtained: 09/11/2004 5:42:50 AM
DHCPServer: 64.58.156.40
DNSDomain: gv.homecable.net
DNSHostName: MyComputer
DomainDNSRegistrationEnabled:
IPAddress: 24.344.56.566
IPAddresslen: 13
IPConnectionMetric: 30
IPEnabled: True
MACAddress: 00:3B:27:43:6A:D1
MTU:


Sub testnicconfigS()
'set reference to WMI for WinXP and 2000
'The Win32_NetworkAdapterConfiguration WMI class represents
'the attributes and behaviors of a network adapter.
'This class has been extended to include extra properties and methods 'that
support the management of the TCP/IP and Internetworking Packet Exchange
(IPX) 'protocols (and are independent of the network adapter).
Dim strComputer As String
Dim objWMIService As Object
Dim colitems As Object
Dim objitem As Object
On Error Resume Next 'there maybe multiple Nic entries that are empty so
skip them

strComputer = "." 'default "." specifies local machine name Set
objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set
colitems = objWMIService.ExecQuery("Select * from
Win32_NetworkAdapterConfiguration", , 48)

For Each objitem In colitems

    Debug.Print "DHCPEnabled: " & objitem.DHCPEnabled
    Debug.Print "DHCPLeaseExpires: " & WMIDateStringToDate
(objitem.DHCPLeaseExpires)
    Debug.Print "DHCPLeaseObtained: " & WMIDateStringToDate
(objitem.DHCPLeaseObtained)
    Debug.Print "DHCPServer: " & objitem.DHCPServer
    Debug.Print "DNSDomain: " & objitem.DNSDomain

    Debug.Print "DNSHostName: " & objitem.DNSHostName

    Debug.Print "DomainDNSRegistrationEnabled: " &
objitem.DomainDNSRegistrationEnabled

    Debug.Print "IPAddress: " & objitem.IPAddress(0)
       'this is an array like other undocumented entries
       'you will have to find by trial and error
       'although there is an isarray property somewhere
       Debug.Print "IPAddresslen: " & Len(objitem.IPAddress(0))
    Debug.Print "IPConnectionMetric: " & objitem.IPConnectionMetric
    Debug.Print "IPEnabled: " & objitem.IPEnabled
    Debug.Print "MACAddress: " & objitem.MACAddress
    Debug.Print "MTU: " & objitem.MTU

Next
End Sub
Function WMIDateStringToDate(dtmInstallDate) As String 'WMI has an odd date
format WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _ & " " &
Mid(dtmInstallDate, 9, 2) & ":" & _ Mid(dtmInstallDate, 11, 2) & ":" &
Mid(dtmInstallDate, _ 13, 2))
End Function


Erwin Craps - IT Helps wrote:

>Shields up is a test a webserver test, but just at the startpage (before
>the test) you can see your dns name and ip address
>
>https://www.grc.com/x/ne.dll?bh0bkyd2
>
>
> 
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve Conklin
>(Developer at UltraDNT)
>Sent: Thursday, September 16, 2004 4:17 PM
>To: 'Access Developers discussion and problem solving'
>Subject: RE: [AccessD] External IP Address of Local Machine
>
>Thanks, Stuart.  
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart
>McLachlan
>Sent: Wednesday, September 15, 2004 7:48 PM
>To: Access Developers discussion and problemsolving
>Subject: Re: [AccessD] External IP Address of Local Machine
>
>
>On 15 Sep 2004 at 18:55, Steve Conklin (Developer at UltraDNT) wrote:
>
>  
>
>>I am using WDSI, WinInet and various API's to get 2 Access 
>>applications to send data to each other over FTP.  It is working well,
>>    
>>
>
>  
>
>>but I want the server to be secure, that is to only allow logins/files
>>    
>>
>
>  
>
>>to come from specific IP's. This is ok when I am sending, because I 
>>know my IP, and I tell the client to allow my IP.  When I (hopefully) 
>>sell a copy to the client's client, how can they easily determine
>>    
>>
>their IP?
>  
>
>>I have looked at the Winsock API and can get remote IP's via Host
>>    
>>
>Name.
>  
>
>>However, when I want to get the IP of the local PC, it returns the 
>>192.168.x.x address; how can I get the external IP that the FTP server
>>    
>>
>
>  
>
>>needs to know through VB/API?
>>
>>    
>>
>
>If you are working through a router, you can't since only the router
>knows 
>the external address..   The only way would be to bounce an HTML request
>of
>an external website and read the return data. There a numbder of
>freeware tools available on the web that do just that. See
>http://www.snapfiles.com/freeware/network/fwip.html for examples
>
>
>If you're machine is directly connected to the Internet, you can iterate
>
>through it's IP adddresses.
>
>Here's a module to do it (watch for linewrap)
>
>Option Compare Database
>Option Explicit
>
>Const MAX_IP = 5   'To make a buffer... i dont think you have more than
>5 ip on your pc..
>
>Type IPINFO
>     dwAddr As Long   ' IP address
>    dwIndex As Long '  interface index
>    dwMask As Long ' subnet mask
>    dwBCastAddr As Long ' broadcast address
>    dwReasmSize  As Long ' assembly size
>    unused1 As Integer ' not currently used
>    unused2 As Integer '; not currently used End Type
>
>Type MIB_IPADDRTABLE
>    dEntrys As Long   'number of entries in the table
>    mIPInfo(MAX_IP) As IPINFO  'array of IP address entries End Type
>
>Type IP_Array
>    mBuffer As MIB_IPADDRTABLE
>    BufferLen As Long
>End Type
>
>Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
>(Destination As Any, Source As Any, ByVal Length As Long) Public Declare
>Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As
>Long, ByVal Sort As Long) As Long
>
>
>Public Function ConvertAddressToString(longAddr As Long) As String
>    Dim myByte(3) As Byte
>    Dim Cnt As Long
>    CopyMemory myByte(0), longAddr, 4
>    For Cnt = 0 To 3
>        ConvertAddressToString = ConvertAddressToString +
>CStr(myByte(Cnt)) + "."
>    Next Cnt
>    ConvertAddressToString = Left$(ConvertAddressToString,
>Len(ConvertAddressToString) - 1) End Function
>
>Public Function IPAddresses() As Long
>Dim lngRetVal As Long
>Dim lngLoop As Long
>Dim bBytes() As Byte
>Dim IPList As MIB_IPADDRTABLE
>
>    GetIpAddrTable ByVal 0&, lngRetVal, True
>
>    If lngRetVal <= 0 Then Exit Function
>    ReDim bBytes(0 To lngRetVal - 1) As Byte
>    'retrieve the data
>    GetIpAddrTable bBytes(0), lngRetVal, False
>      
>    'Get the first 4 bytes to get the entry's.. ip installed
>    CopyMemory IPList.dEntrys, bBytes(0), 4
>
>    For lngLoop = 0 To IPList.dEntrys - 1
>        'Copy whole structure to Listing..
>        CopyMemory IPList.mIPInfo(lngLoop), bBytes(4 + (lngLoop *
>Len(IPList.mIPInfo(0)))), Len(IPList.mIPInfo(lngLoop))
>         Debug.Print "IP address                   : " &
>ConvertAddressToString(IPList.mIPInfo(lngLoop).dwAddr)
>         Debug.Print "IP Subnetmask            : " &
>ConvertAddressToString(IPList.mIPInfo(lngLoop).dwMask)
>         Debug.Print "BroadCast IP address  : " &
>ConvertAddressToString(IPList.mIPInfo(lngLoop).dwBCastAddr)
>         Debug.Print "**************************************"
>    Next
>
>End Function
>
>
>--
>Stuart
>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list