Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ipconfig ? ipaddress, subnet & Def' Gateway.
Message
 
To
23/10/2004 14:16:01
Carl Dobson
Reference Point Computers
Overbury, Tewks, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows XP SP2
Miscellaneous
Thread ID:
00954023
Message ID:
00954050
Views:
23
>I need to get the values of the IP Address, Subnet Mask & Default Gateway Values (Basically everything that running IPCONFIG would give you). I cant find anything in the help file which would point to retrieving this information.


IF you have one of the following:

Client: Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0 SP4 and later.

you can use WMI to get this information, something like:
local loWMIService, loWBEMLocator, loLocator, loNACs, loNAC, lcGW, lcIPAddress, lcIPSubnet

clear
TRY
	loWBEMLocator	= createObject("wbemScripting.SwbemLocator")
	loWMIService	= loWBEMLocator.ConnectServer()
CATCH
	loWMIService	= null
ENDTRY

IF not Isnull(loWMIService)
	loNACs			= loWMIService.ExecQuery('Select * from Win32_NetworkAdapterConfiguration where IPEnabled=True')
	for each loNAC in loNACs
		WITH loNAC
			? "Caption			: ", .Caption
			? "Description		: ", .Description
			? "DNS Domain		: ", .DNSDomain
			? "DNS Host Name		: ", .DNSHostName
			? "MAC Address		: ", .MACAddress
			? "Database Path	: ", .DatabasePath
			IF NOT ISNULL(.DefaultIPGateway)
				FOR EACH lcGW IN .DefaultIPGateway
					? "Default Gateway		: " + lcGW
				ENDFOR
			ENDIF	
			IF NOT ISNULL(.IPSubnet)
				FOR EACH lcIPSubnet IN .IPSubnet
					? "Subnet Mask		: ", lcIPSubnet
				ENDFOR
			ENDIF
			IF NOT ISNULL(.IPAddress)
				FOR EACH lcIPAddress IN .IPAddress
					? "Ip Address		: ", lcIPAddress 
				ENDFOR
			ENDIF
		ENDWITH
	ENDFOR
ENDIF
RETURN
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Reply
Map
View

Click here to load this message in the networking platform