Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IP address
Message
From
28/02/2011 04:24:13
Sharath Shetty
Sri Krishna Consultancy Services
Mumbai, India
 
 
To
27/02/2011 23:55:56
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
01502045
Message ID:
01502064
Views:
93
>how can I know my own IP address?
>
>thanks for the help


This is the VFP Code i am using to find Local IP Address

Author unknown, might be from UT
FUNCTION GetIPAddress 

lcComputer = "." 
loWMIService = GetObject("winmgmts:\\" + lcComputer + "\root\cimv2") 
IPConfigSet = loWMIService.ExecQuery ; 
("Select IPAddress from Win32_NetworkAdapterConfiguration") 
For Each IPConfig in IPConfigSet 
If ! IsNull (IPConfig.IPAddress) 
*!*	  ? "Adresse IP:"+IPConfig.IPAddress(0) 
*!*	  ? "Adresse MAC:"+IpToMacAddress(IPConfig.IPAddress(0)) 
 cAddress= "IP:"+IPConfig.IPAddress(0)+"; MAC:"+IpToMacAddress(IPConfig.IPAddress(0))
 exit
endif 
next 
RETURN cAddress


FUNCTION IpToMacAddress(lcIP) 
        DECLARE INTEGER inet_addr IN ws2_32.dll STRING cIP 
        DECLARE INTEGER SendARP IN iphlpapi.dll; 
                INTEGER destIP, INTEGER sourceIP,; 
                STRING @ pMacAddr, INTEGER @ PhyAddrLen 
        LOCAL lnHr, lnIpAddr, lcMacAddr, lnLen 
        lnIpAddr = inet_addr(lcIp) 
        lcMacAddr = REPLICATE(CHR(0),6) 
        lnLen = 6 
        lnHr = SendARP(lnIpAddr,0,@lcMacAddr,@lnLen) 
        RETURN BinaryToMac (lcMacAddr, lnLen) 
ENDFUNC 

FUNCTION BinaryToMac(lcMacAddr, lnLen)
        LOCAL lcMac, xj
        lcMac = ""
        FOR xj = 1 TO lnLen - 1
                lcMac = lcMac + RIGHT(TRANSFORM(ASC(;
                        SUBSTR(lcMacAddr,xj,1)),"@0"),2) + ":"
        ENDFOR
        lcMac = lcMac + RIGHT(TRANSFORM(ASC(;
                SUBSTR(lcMacAddr,lnLen,1)),"@0"),2)
        RETURN lcMac
ENDFUNC
Previous
Reply
Map
View

Click here to load this message in the networking platform