Steve Conklin (Developer@UltraDNT)
Developer at UltraDNT.com
Thu Sep 16 09:16:46 CDT 2004
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
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com