How to get IP Address using Foxpro Command

Asked By 0 points N/A Posted on -
qa-featured

Hi

I need to know if someone sends me file via an email attachment, and if I want to know his IP address using Foxpro command when he is connected to the internet, then is it really possible to get his IP? I need to know this urgently, as I am getting sensitive emails from someone regularly, but after opening that I found it false. Before taking legal action I need to be sure about his IP Address. So can anyone please inform me the process of retrieving the IP address using Foxpro Command.

Thanks

SHARE
Best Answer by Baldwin Coll
Answered By 0 points N/A #164702

How to get IP Address using Foxpro Command

qa-featured

Hello,

If you wish your visual Foxpro program to learn the IP address of the computer it is running on and that of others on the LAN, I have come across some code segment that can help achieve just that.

1.      Check out the following link for the code segment  

https://www.foxite.com/archives/how-to-get-ip-address-programatically-0000269533.htm

2.      another code segment on the same is given in the link below

https://www.foxite.com/faq/default.aspx?id=47

Best Answer
Best Answer
Answered By 0 points N/A #164703

How to get IP Address using Foxpro Command

qa-featured

Every now and then you might need the local IP address of the machine one application is running on.

I just recently had this situation anyway.
Looking around a bit I found a simple way to do this.
First of all, create an instance of the winsock.ocx as in 
osck = Create Object(\"MSWinsock.winsock.1\")
 
Then read the LOCAL IP property of that object.
osck.localIP
 
if it returns 127.0.0.1 you can bet you are NOT connected to a network, otherwise it will return the localIP address which can be used for any purpose.
 
Based on a reply by Bernard Bout after I posted this FAQ I have to say that the winsock control has serious memory leaks which could lead to hanging your machine.
Bernard posted the following code that also retrieves the local IP address for you, without use of winsock controls. Kudos to Bernard for sharing this with us.
 
Here is the code:
PROCEDURE GetIP
LPARAMETER pcItem
LOCAL lcItem
lcItem = iif( vartype(pcItem)=\'C\', upper(pcItem), \'NONE\' )
#DEFINE ERROR_SUCCESS           0
#DEFINE ERROR_NOT_SUPPORTED     50
#DEFINE ERROR_INVALID_PARAMETER 87
#DEFINE ERROR_BUFFER_OVERFLOW   111
#DEFINE ERROR_NO_DATA           232
 
#DEFINE MAX_ADAPTER_NAME_LENGTH        256
#DEFINE MAX_ADAPTER_DESCRIPTION_LENGTH 128
#DEFINE MAX_ADAPTER_ADDRESS_LENGTH     8
 
DECLARE INTEGER GetAdaptersInfo IN iphlpapi;
    STRING @pAdapterInfo, LONG @pOutBufLen
 
LOCAL lcBuffer, lnBufsize
lnBufsize = 0
lcBuffer = \"\"
 
* this call usually returns the ERROR_BUFFER_OVERFLOW
* with lnBufsize set to the required amount of memory
GetAdaptersInfo(@lcBuffer, @lnBufsize)
 
lcBuffer = Replicate(Chr(0), lnBufsize)
IF GetAdaptersInfo(@lcBuffer, @lnBufsize) <> ERROR_SUCCESS
  * still something is wrong
  RETURN \"\"
ENDIF
 
*|typedef struct _IP_ADAPTER_INFO {
*|  struct _IP_ADAPTER_INFO* Next;         0:4
*|  DWORD ComboIndex;                      4:4
*|  char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];          8:260
*|  char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]; 268:132
*|  UINT AddressLength;                       400:4
*|  BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]; 404:8
*|  DWORD Index;                              412:4
*|  UINT Type;                                416:4
*|  UINT DhcpEnabled;                         420:2
*|  PIP_ADDR_STRING CurrentIpAddress;         ?? 4 byte pointer ??
*|  IP_ADDR_STRING IpAddressList;             433:15
*|  IP_ADDR_STRING GatewayList;               
*|  IP_ADDR_STRING DhcpServer;                
*|  BOOL HaveWins;
*|  IP_ADDR_STRING PrimaryWinsServer;
*|  IP_ADDR_STRING SecondaryWinsServer;
*|  time_t LeaseObtained;
*|  time_t LeaseExpires;
*|} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
 
* wgcs: Experimentally found indices:
*   NetMask       449:15
*   Gateway       473:15
*   dhcp          513:15
*   Wins Server   557:15
*   
 
do case
  case lcItem=\'NONE\'
    RETURN STRTRAN(SUBSTR(lcBuffer, 433,15), Chr(0),\"\")
  case lcItem=\'IP\'
    RETURN STRTRAN(SUBSTR(lcBuffer, 433,15), Chr(0),\"\")
  OTHERWISE
  RETURN \"\"

Related Questions