Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I get the host IP with VFP?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01294826
Message ID:
01294829
Vues:
16
This message has been marked as the solution to the initial question of the thread.
>How can I get the IP of the host?
>Is there a WinAPI I can call?
>Where can I found it?

I use the following methods of a class to do it (I found them here on UT somewhere)..

FUNCTION ip_address

LOCAL lnRecords as Integer
LOCAL lcAddress as String, lcMask as string
LOCAL lcIP_Address as String
LOCAL pdwSize as Integer
LOCAL pIpAddrTable as String

DECLARE INTEGER GetIpAddrTable IN iphlpapi;
STRING @ pIpAddrTable,;
INTEGER @ pdwSize,;
INTEGER bOrder
DECLARE STRING inet_ntoa IN ws2_32 INTEGER in_addr

lcIP_Address = ''

pdwSize =0
=GetIpAddrTable (NULL, @pdwSize, 1)

pIpAddrTable = REPLICATE(CHR(0), pdwSize)
=GetIpAddrTable (@pIpAddrTable, @pdwSize, 1)

lnRecords = This.buf2dword(SUBSTR(pIpAddrTable, 1, 4))

FOR i=1 TO lnRecords
lcIP_Address = INET_NTOA(this.buf2dword(SUBSTR(pIpAddrTable, 5 + (i-1)*24, 4)))
lcMask = INET_NTOA(this.buf2dword(SUBSTR(pIpAddrTable, 13 + (i-1)*24, 4)))
IF !EMPTY(lcIP_Address) AND lcIP_Address<>'127.0.0.1'
exit
endif
NEXT

RETURN lcIP_Address

ENDFUNC && IP_Address

FUNCTION buf2dword(cBuffer)

RETURN Asc(SUBSTR(cBuffer, 1,1)) + ;
Asc(SUBSTR(cBuffer, 2,1)) * 256 +;
Asc(SUBSTR(cBuffer, 3,1)) * 65536 +;
Asc(SUBSTR(cBuffer, 4,1)) * 16777216

ENDFUNC && buf2word
____________________________________

Don't Tread on Me

Overthrow the federal government NOW!
____________________________________
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform