WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

WinItemNameId and IP address

Keywords:  WinIdGet WinItemNameId ItemLocate WinId IP addresses	 winipcfg  MAC

Question:

How can I get the dynamic IP address for an active Window, in Windows 95?

Answer:

Here's an example: Also look in the Internet Extender database area of this website, for more examples.
;------------------snip--------------

;Gets your dynamic IP address in win95. 

        Run("C:\WINDOWS\WINIPCFG.EXE", "") 
        WinId = WinIdGet("IP Config") 
        WinIconize(WinId) 
        a=WinItemNameId() 
        b=ItemLocate(WinId,a,"|") 
        title=ItemExtract(b-1,a,"|") 
        WinClose(WinId) 
        Message("Your current IP address is", title)

NOTE: There's an undocumented command-line switch for winipcfg.exe.

	WINIPCFG /BATCH filename
It writes the IP information to a text file.
	WINIPCFG /ALL
Brings out the More Info screen.

Your best bet on this one is to include BOTH of the command line switches (/BATCH and /ALL) to get MAC address info and pipe this to a temporary file (use TEMP environment variable) which is then parsed for the string(s) required.

For example,

	RunHideWait("winipcfg.exe","/batch /all c:\temp\winipcfg.txt")
(or replace the c:\temp with the ENV Var settings for it)

Note that if you do this on a system with Dial Up Networking installed, you will ALSO get a MAC address for the DUN adapter (modem)

Try just running the command from a command line piping to a filename to see the information presented and determine the best way to parse the (text) file.

For more information on this topic, also see Article #W13483.


Here is yet another method to determine your IP address on Windows 95 machines. It has the advantage of using the registry rather than launching a separate app.
;--- Subroutine WhatIsMyIP
;    Assigns the current IP from the registry to MyIP.	MyIP is set to 0.0.0.0
;    if the IP cannot be determined.
;    Mike Smith, Queen's University, smithm@post.queensu.ca
:WhatIsMyIP
   wimem = ErrorMode(@off)
   LastError() ; Reset the error to 0
   wimKey = RegOpenKey(@RegMachine,"System\CurrentControlSet\Services\Class\NetTrans")
   if LastError() == 0
      wimi = 0
      wimItem = RegQueryKey(wimKey,wimi)
      while wimItem != ""	  
	 wimSubKey = RegOpenKey(@RegMachine,"System\CurrentControlSet\Services\Class\NetTrans\%wimItem%")
	 MyIP = RegQueryValue(wimSubKey,"[IPAddress]")
	 RegCloseKey(wimSubKey)
	 if MyIP != "0" then break
	 wimi = wimi + 1
	 wimItem = RegQueryKey(wimKey,wimi)
      endwhile
      RegCloseKey(wimKey)
   else
      MyIP = ""
   endif
   ErrorMode(wimem)
   for wimi=1 to 4
      if !IsNumber(ItemExtract(wimi,MyIP,"."))
	 MyIP = "0.0.0.0"
	 break
      endif
   next
   Drop(wimem,wimKey,wimSubKey,wimi,wimItem)
   return
;--- End Subroutine WhatIsMyIP	 

And another user provided the following:
;Simple Script that works for me when trying ;to lookup my Ip Address
;98/08/04 John Henry Miller
;jhmiller@mindless.com

;Script to keep checking (looping) looking for my IP Address
;Once IP Address is established, it is displayed in a window and script is terminated.

AddExtender("WWWSK34I.DLL")
host="ftp.execpc.com"

:Start
GoSub GetIpAddress

If IpAddress!=0
  ;IpAddress!=0 then we are on Internet so let's tell the world and quit looking.
  Message("Now on Internet!", "My IP Address is %IpAddress%")
  Exit
Else
  ;IpAddress==0 then we are not yet on Internet, so don't do anything but keep looking.
EndIf

;Put in a little delay to free up CPU time.
TimeDelay(5)
GoTo Start

:GetIpAddress

:ConnectToHost 
  ;Get the Ip Address for this machine by opening and connecting a socket to a known host.
  talksocket=sOpen()
  status=sConnect(talksocket,"%host%","ftp")

  ;This is where we get the IpAdress with the Socket number.

  IpAddress=wxGetInfo(1,talksocket)

  ;Find the colon which is the charecter used to 
  ;parse the Ip Adress from the Socket Number.

  colon= StrIndex(IpAddress, ":", 0, @FWDSCAN)-1

  ;Strip off the Socket Number.

  IpAddress=StrSub(IpAddress, 1, colon)  

  ;All done with this Socket

  sClose(talksocket)
Return

Article ID:   W13120
Filename:   WinItemNameId and IP address.txt
File Created: 2001:03:01:14:43:14
Last Updated: 2001:03:01:14:43:14