Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Obtaining your local IP address
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Obtaining your local IP address
Miscellaneous
Thread ID:
00505053
Message ID:
00505053
Views:
62
I've spent a fair amount (too much) time on this and wanted to share my findings.

If you are using an interactive application with a form that you can drop the winsock control onto, you can use that with the LocalIP property.

If you are working with a .DLL, it seems parsing the return from IPCONFIG is the best answer:
local lcTempFile, loWSH, lcLocalIP
lcTempFile="LocalIP.txt"
if file(lcTempfile)		&&erase leftovers from old run
  erase (lcTempFile)
endif
loWSH=CreateObject("Wscript.Shell")
loWSH.run("command /c ipconfig > "+lcTempfile,0,1)
if file(lcTempFile)		&&read the file and parse it
  lcLocalIP=upper(filetostr(lcTempFile))
  lcLocalIP=substr(lcLocalIP, at('IP ADDRESS',lcLocalIP))
  lcLocalIP=substr(lcLocalIP, at(':',lcLocalIP)+2)
  lcLocalIP=substr(lcLocalIP, 1, at(chr(13),lcLocalIP)-1)
  &&messagebox(lcLocalIP)
endif
This example uses windows scripting host. The second parameter tells it to not display the window, the last parameter tells it to not return until the program is finished.

It's a very cool way to run DOS commands without them flashing on the screen.
Next
Reply
Map
View

Click here to load this message in the networking platform