Novell Home

Getting IP Address Details via an App Object

Novell Cool Solutions: Trench

Digg This - Slashdot This

Updated: 19 Sep 2006
 

Recently we posted this OPEN CALL, and got some great suggestions. Check 'em out, and if you have anything to add, let us know.

Question: Paul K. wrote: I'm trying to make a ZEN app that records the user's IP address, MAC address, User name, time and date to a log file. I'm using variables to do this but I can't seem to find one that has the IP address. Is there one?

Answer: Hmm - there are several ways to get this- but nothing that's easy. Effectively, you need to use IPCONFIG and grep for the IP address details; there are WMI APIs to get this too. OPEN CALL: Anyone have some ideas for Paul? Let us know...

Suggestions

Matt Varela

  1. Setup a VERY simple app that doesn't do much - set to 'install only' and 'distribute always.'
  2. Under common/reporting, set check 'Log to File' next to 'Distribution Success' and set a log file location. Associate away!

Among other things, the log will record:

  • Distinguished user name
  • NDS Workstation Name (MAC Address is an option for the rules of import)
  • IP Address
  • Date\Time the app was run

This can, of course, be imported into Access and queried to one's desire.

Nick Gastuch

Here is a visual basic script I wrote to get the IP address and put it into an environmental variable. I started with a vbs function that Jim Shank wrote in his ZENworks Cool Solution Article ?Automated ZEN Imaging: The Next Step?. His program returned the first IP address found by running either ?winipcfg' or ?ipconfig' depending on the operating system. I found that on some of our machines with a VPN client installed, the first address may not be valid. I modified the routine to look for a non-zero subnet mask before saving the IP address. Once I had the IP address, I placed it in the environmental variable ?IPADDR?. The variable is valid only during the current logon session.

Download Nick's Script

Peter Sullivan

Two ways of getting the IP address spring to mind:

1. If the workstation is imported, you could get the workstation object to take the IP address and MAC address as part of the name. Our workstations use the workstation name and the MAC address: e.g WS-12345-00BCF4A358D2 where WS-12345 is the computer name. Extra hyphens can be easily inserted into the object name. How then to get that to a file....?

2. A neater way would be to extract the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Novell\Workstation Manager\Identification\Registration Object. This string contains all the information required. Again, you need a way to get it to a file, but a simple VB app could do this.

Todd Bowman

We use a simple batch file to record IP addresses at login. We do this to avoid pushing out large updates to users who may be dialing in or across the WAN. I didn't write the script, I got the IP part of it from a guy in a Novell class a few years ago and have tweaked it to suit our needs.

There are two versions of the script, one for Win9x users, one for NT or better. The change required is noted in the script. The login script calls the correct one based on the platform variable.

The whole thing runs in just a few seconds, as it does all the file writing and processing on the local workstation.

Here is our batch file.

Mikael Rydberg

One easy way to get the IP address from a workstation in to a file is to use the macro P_STATION in an application object and push it to a textfile through the distribution/text file option. If you use P_STATION in the login script it will return the MAC address, but when you use it in an application object it will return the IP address of the workstation. I haven't tried this in a mixed IP/IPX environment but in a pure IP environment it works like a charm.

Keep up the good work!!

Ron Zink

There is an ODBC driver offered by Novell for eDirectory that can be used to get all kinds of details from workstation objects. I use this driver constantly to report the existing objects that are in the tree. Use Microsoft Excel or Access to connect to eDirectory and you can get the IP address and other details you need.

Elliott Allen

Go to www.sysinternals.com and look for a free 450K program called BGInfo. Put it in your login script and it will gather all the info you requested and much more for any Windows operating system and put it in a txt, xls, mdb file or out to an SQL server. You can have all your networked PC's logging their info to one log file. It's customizable to record any registry key or file existence, etc, and will put the info on the user's desktop over their wallpaper, replace their wallpaper or keep in their system tray. We have been using it for about two years.

Gilles Normandeau

Why use ZENworks? NLIST works well, as do many other NDS query tools such as NDSExporter. Here is a sample query entered at a console window and redirected to a text file.

nlist workstation show "WM:NAME User" "WM:User History" "WM:Network
Address">workstations.txt

The format under NLIST not what you want? Try NDSExporter which will export to a text file with one record per line. The file can then be imported by another program such as EXCEL or ACCESS for further sorting if you want. Results are more quickly achieved than by creating and distributing a ZEN Application and waiting for the log files to be updated.

Alan Sickels

This assumes one nic, only works with NT/2000 (and XP with slight change), and requires several apps.

Add to the app object requirements the existence of the key "HKLM,SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1" Use the app object "Run before Launching" script to REGREAD "HKLM,SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\1,ServiceName" Also in the script DOS SET MYNIC="%99"

Still in the same launch script you can now extract the IP address by REGREAD "HKLM,SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%<MYNIC>,IPAddress" For Windows XP REGREAD "HKLM,SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%<MYNIC>,DhcpIPAddress" One more DOS SET IPADDR="%99" and you now have the PC's IP Address.

You need several apps because the location of the first REGREAD can vary. My WinXP laptop is at "3" and my Win2K desktop is at "6". Don't forget to change both the requirement and the REGREAD to match. I've never seen anything above 8.

If you have a mixed NT/2000/XP environment you can either double the number of objects and set execution with System Requirements or you should be able to check the WINVER paremeter (but I have not tested this).

Attached is the application export in AXT form.

If you have any questions you may contact Alan at ASickels@SunMaid.com

Damien Schmitt

This very simple script uses Windows Management Instrumentation and works natively on Windows 2000/XP. You must download Windows Management Instrumentation (WMI) CORE 1.5 for Windows 95/98/NT 4.0 (availaible separately for Win 9x and NT 4). All information is dynamic, WMI for IP infos, NT Environnment variable for NetWare username and system date and time (so nwserver date and time set by the client 32) and registry for NDS WSName.

The file is comma-separated, so you can easily import it into a database such as Access or MySql.

If you have any questions, comments or if this script doesn't respond to all of your needs you can contact me at damien.schmitt@dames-network.com.

Enjoy !

Download logging.zip

Thore Andersson

Try this:

Create a Force Run, Distribute Always NAL app that writes a new line to a log file every time the user logs on.

%LOGG_PATH%\MacKoll.txt
(+) %WORKSTATION_DN%,(%NETWORK%:%PHYSICAL_STATION%,%OS%
 %OS_VERSION%),%CN%,%REQUESTER_CONTEXT%,(%GIVEN_NAME% %LAST_NAME% %L%
  %OU%),%YEAR%-%MONTH%-%DAY%,%HOUR24%:%MINUTE%

Feedback: I don't understand how to set up the suggestion by Thore Andersson. Could someone provide more details on how to set this up? Where is this information entered? Is it in the "Reporting" window where you enter a log file path?

NEW Thore has graciously provided a detailed explanation of how to implement his suggestion. Check out this article.

Shawn

The following line will isolate the IP address and put it into an environment variable. I found it while cruising the web and modified it only slightly. The line is called in a batch file and assigns the value to the variable IPADDRESS. The problem is, however that the environment variable setting is lost as soon as the DOS window closes.

It is all one line and works in Windows 2000. Because of the FOR statements, I don't think it will work in Win9x.

FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG ^| FIND "IP Address"') DO FOR %%B IN (%%A) DO SET IPADDRESS=%%B

If anyone knows how to get the batch file to set the environment variable so that it keeps the value assigned even after the DOS window closes, I would really appreciate hearing about it.

Donald Krebel

I'd like to respond to Shawn! If you want to have a permanent environment variable in the system, use the utility Setx. Just add the next line below:

FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG ^| FIND "IP Address"') DO FOR %%B IN (%%A) DO SET IPADDRESS=%%B  

setx IPA %IPADDRESS% -m

Sande Nissen

Shawn wrote: "... If anyone knows how to get the batch file to set the environment variable so that it keeps the value assigned even after the DOS window closes, I would really appreciate hearing about it."

Shawn, you need one of the little gems from the free Microsoft Windows XP Support Tools (known as the Resource Kit in Windows 2000). SETX.exe will do what you want. Like all the Support Tools/Resource Kit tools, it does not have to be installed on a workstation before using it.

Here's an excerpt from its documentation page:

Setx.exe

This command-line tool offers a batch method for setting environmental variables in the user or system environment and requires no programming or scripting. In addition to taking an environmental variable and its associated value from the command line, it can also get the values of registrykeys and write them to text files.

SetX provides the only command-line or programmatic way to directly set system environment values for Microsoft Windows 2000. System environment variables are manually configureable through Control Panels or through a registry editor (Regedit or Regedt32). The SET command, which is internal to the command interpreter (Cmd.exe), sets only user environment variables for the current console window.

You can use SetX to set values for user and system environment variables from one of three sources: Command Line Mode, Registry Mode, or File Mode.

To display command-line options and details about syntax for all three modes, type:
setx /? or setx (without parameters)

For additional information and examples for all three modes, type:
setx -i

Bart de Ruiter

Check out this Freeware tool: BgInfo. You can find it here.

Use option:

File|Database: Specifies a .XLS, .MDB or .TXT file or a connection string to an SQL database that BGInfo should use to store the information it generates. Use this to collect a history of one or more systems on your network. You must ensure that all systems that access the file have the same version of MDAC and JET database support installed. It is recommended you use at least MDAC 2.5 and JET 4.0. If specifying an XLS file the file must already exist

David Frey

As mentioned there are several ways.

Batch/CMD file syntax:

@echo off
rem Get IP Address using ipconfig; parse output using "for" 
command
rem tokens=15 is for 2K,XP...tokens=12 is for NT4
  for /f "tokens=15" %%a in ('ipconfig ^| find "IP Address"') 
do set IPAddress=%%a
if "%IPAddress%"=="" for /f "tokens=12" %%a in ('ipconfig ^| 
find "IP Address"') do set IPAddress=%%a

Note: if more than one network interface, the above will select the last in the list.

vbscript syntax for WMI script:

On Error Resume Next
Dim sComputer
Dim oWMIService, oItem
Dim propValue
Dim SWBemlocator
Dim cItems

sComputer = "."
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set oWMIService = GetObject("winmgmts:\\" & sComputer 
& "\root\cimv2")
Set cItems = oWMIService.ExecQuery("Select * from 
Win32_NetworkAdapterConfiguration",,48)
For Each oItem in cItems
	for each propValue in oItem.IPAddress
		WScript.Echo "IPAddress: " & propValue
	next
Next

Note: the sample vbscript only outputs to screen. Additional coding is required.

Andre Sumara

AutoIT version 3.x (free from www.hiddensoft.com/autoit) has built-in macros for gathering system information. The @IPAddress macro can get up to four IP addresses from a machine if you have multiple NICs.

Sample script :

MsgBox (0, 'Get IP Address', "IPAddress1=" & @IPAddress1 & "
IPAddress2=" & @IPAddress2 & " IPAddress3=" & @IPAddress3 & "
IPAddress4=" & @IPAddress4)

You can compile the script to exe as well if required. Hope this helps!

Elmar Schmidlin

Don't forget the loginscript where you have the Variable NETWORK_ADDRESS and many others.

In the company I worked before I started at Novell, we used it to know where the WS is located and then to map drives (SYS, Public, APPS) locally.

In all documents I saw, I never see that NETWORK_ADDRESS can give you the IP address -- we always have examples with IPX addresses.

Would be a good thing to make two examples, one with IPX and one with IP.

Please feel free to contact me if you want to know more or if you have questions.

Mike Harris

The WinBatch scripting/automation language (www.winbatch.com) comes with a NetwareX extender that one can use to view/change information in NDS/eDirectory objects, such as workstation objects. A free, fully functional, time-limited download of WinBatch is available for evaluation purposes. The NetwareX extender help file contains discussions of two particularly useful functions and associated example code that one can quickly try out, nwGetObjInfo (object type, etc.) and nwGetObjValue (object attribute names and their contents).

For workstation objects, such information includes: ZEN:INV OS Type, ZEN:INV OS Revision, ZEN:INV Computer Type, ZEN:INV Computer Model, ZEN:INV Processor Type, ZEN:INV BIOS Type, ZEN:INV Memory Size, ZEN:INV Disk Info, ZEN:INV Last Scan Date, zenzfdVersion, ZEN:INV Novell Client Version, WM:Network Address (may contain more than one address and may contain both IP and IPX addresses), zenwmMACAddress, zenwmSubnetMask.

Note that the majority of these are created/collected via the use of ZENworks.

Beyond this, ZENworks workstation inventory apparently collects and maintains even much more detailed workstation invntory information in an inventory database separate from NDS/eDirectory, which can be queried/reported via ZENworks (and presumably other tools).

Jos Burger

Sysinternals has a solution for this. They have a free tool called Bginfo.exe.

This tool writes system information like IP address, MAC address, etc. on the user's desktop background.

It is also possible to configure this tool to dump the information in a database and keep the user's background untouched.

Éric Drouin

We are using EPO (Epolicy Orchestrator) from Network Associates to update and manage Mcafee ViruScan. In the registry, under HKLM,SOFTWARE\Network Associates\ePolicy Orchestrator\Agent , there is IPADDRESS that contains the IP address of the workstation. In the login script, we use the REGREAD command and set a Windows variable for IP addresses.

REGREAD "HKLM,SOFTWARE\Network Associates\ePolicy Orchestrator\Agent,IPAddress" SET IP="%99"

IP is a Windows variable that can be used to store information into a file.

Matthew Kilman

I know this is an old discussion, but I had to add to it. My solution will check for the IP address and then record that IP address to a variable, IPADDRESS. This batch file works by using IPCONFIG piped into the FIND command in conjunction with a FOR IN DO loop. It runs a little slow on older PC's, but still works well. By tweaking it to use WINIPCFG /BATCH, you can use it on a Windows 9x machine.

Download batch files.

Randy Upton

Here's a solution I use.

'Written by Randy Upton, Clark County School District
'? 2/10/2005


On Error Resume Next 
'*************IP Address Values
Dim Stage1
Dim Stage2
Dim Stage3
Dim Mac_Addr
Dim Subnet
Dim DHCP_E
Set Registry = CreateObject("Wscript.Shell") 
Set FileSystem = CreateObject("Scripting.FileSystemObject") 
Set Network = CreateObject("WScript.Network") 
Set WshShell = WScript.CreateObject("WScript.Shell")

'***********Resolve IP Address XP
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objAdapter in colAdapters
	Stage1 = objAdapter.IPAddress(0)

	If Left(Stage1,3) = "10." Then 'I restrict my addresses to a 10. network, so...
		Stage2 = objAdapter.IPAddress(0)
		Mac_Addr = objAdapter.MACAddress(0)
		Subnet = objAdapter.IPSubnet(0)
		DHCP_E = objAdapter.DHCPEnabled(0)
		If DHCP_E = "True" Then
			DHCP_E = "Yes"
		Else
			DHCP_E = "No"
		End if
	End If
Next


'Following line is for testing - remove for operation
wscript.echo "IP Address = " & Stage2 & vbcrlf & "MAC Address = " & Mac_Addr

'If you want to record the data you will need to give rights to all users to the folder containing 'your (Access) database.  

'This code sample allows you to write to the database IF YOU CREATE IT!
'****************** Destination file routine
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Dim Resp
DestFile = "\\10.4.0.16\data\ZEN\WSinfo\AUDIT.mdb"

'****************** Check for file exist- create if necessary and add header and ws entry
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")



	Set objConnection = CreateObject("ADODB.Connection")
	Set objRecordset = CreateObject("ADODB.Recordset")

	objConnection.Open _
    	"Provider = Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source = \\10.4.0.16\data\ZEN\WSinfo\AUDIT.mdb" 
	objRecordset.CursorLocation = adUseClient
	objRecordset.Open "SELECT * FROM Audit" , objConnection, _
    	adOpenStatic, adLockOptimistic
	strSearchCriteria = "Mac_Address = " & Mac_Addr  
	objRecordSet.Find strSearchCriteria

	If not objRecordSet.EOF Then
		objRecordSet("Mac_Address") = Mac_Addr
		objRecordSet("Date") = Date
		objRecordSet("Time") = Time
		objRecordSet("IP_Address") = Stage2

		objRecordSet.Update
		objRecordset.Close 
		objConnection.Close

	Else

		'WRITE NEW IF NOT FOUND

		objRecordSet.Open "SELECT * FROM Audit" , _
    		objConnection, adOpenStatic, adLockOptimistic

		objRecordSet.AddNew
		objRecordSet("Mac_Address") = Mac_Addr
		objRecordSet("Date") = Date
		objRecordSet("Time") = Time
		objRecordSet("IP_Address") = Stage2

		objRecordSet.Update

		objRecordSet.Close
		objConnection.Close
	End If
Wscript.quit

NOTE: I record information from 100,000 workstations - this can leave a large number of open connections on your server. I recommend using an SQL database if you have access to one. All you have to do is change the objConnection information to point to SQL.


In the path to executable I put a copy of wscript.exe on my server (the IP address in the path) so I don't have to depend on the workstation having a copy or rights or whatever.

Cory O'Brien

Here's a batch file I was calling from the login script to keep track of who was logging on where and how often and to grab a unique setting from an ini file and log it. It creates a text file with the user's Novell user name and then appends that file to another text file in CSV format before deleting it (kind of messy). Yes, the file grew pretty quickly (around 500 users), but the whole purpose was to generate info for an Access database to import when opened and it had an option to keep the latest data (note the dates and times below) and purge old stuff.

I've kept it around because the For statements are very handy for other things also. I've come back to it many times for reference.

@echo off
 
set PCINFO="Path where my results go..."
set INI_PATH="Path to ini file..."
 
@For /F "tokens=16 delims= " %%A in ('IPConfig /ALL ^| Find /I "Host Name"') Do Set host_var=%%A      #There is a space after delims= unless there is a different character.
@For /F "tokens=15 delims= " %%B in ('IPConfig /ALL ^| Find /I "IP Address"') Do Set ip_var=%%B
@For /F "tokens=13 delims= " %%C in ('IPConfig /ALL ^| Find /I "Default Gateway"') Do Set dg_var=%%C
@For /F "tokens=12 delims= " %%D in ('IPConfig /ALL ^| Find /I "Physical"') Do Set mac_var=%%D
@For /F "tokens=2 delims==" %%E in ('type "%OMMITTING_PATH%\MY.ini" ^| Find "INI_SETTING"') Do Set myini_var=%%E
@For /F "tokens=2" %%F in ('date /t') Do Set date=%%F
@For /F "tokens=1 delims= " %%G in ('time /t') Do Set time=%%G
@For /F "tokens=2 delims= " %%H in ('time /t') Do Set ap=%%H
 
@echo "%nwusername%","%myini_var%", "%host_var%","%ip_var%","%dg_var%","%mac_var%","%date%","%time% %ap%" > %PCINFO%\%nwusername%.txt
 
@type %PCINFO%\%nwusername%.txt >> %PCINFO%\all.txt
 
@del %PCINFO%\%nwusername%.txt
 
:END
CLS

Bas Penris

There is a very easy way of doing this. Actually, there is more then one - this one is specifically for NT/2K/XP/2K3/Vista

The way described here is, in my own opinion, the nicest.

Get the freeware blat command line email utility

Now create a batch file and put this in:

Ipconfig /all >%COMPUTERNAME%.TXT
Blat %COMPUTERNAME%.TXT -to your.emailaddress@yourcompany.tld -subject "IP Address of %COMPUTERNAME% for User %USERNAME%" -server <ipofsmtpserver> -f ?ipsender@yourcompany.tld? -priority 1

Explanation

  • %COMPUTERNAME% is the standard Windows variable for your computername
  • %USERNAME% is the active current user
  • <ipofsmtpserver> is your SMTP server. It has to accept messages from IP addresses within the same subnet and relay it if the receiver has the correct domain. See your documentation on how to do that.
  • ?ipsender@yourcompany.tld? Replace this with a recognizable address, which is unique, so it's easy to create rules in your mailclient for sorting.
  • The -priority 1 isn't all too important, but if your mailsystem is crowded, you'll get the mail faster.

Darrell Eddy

Using the free tool BGinfo from Sysinternals, I created an application object in ZfD 6.5 called Sysint-BgInfo



I added a description for the application explaining what it accomplishes.



To keep systems organized, I put utilities such as this in a folder on the root of the PC called Utils. Under distribution Options, in the Application Files section, I have the App object create the directory if it does not exist.



As you can see from the Run Options tab, in the Application section, I use a macro to specify the location of the application executable. Under parameters, I specify the bgi file, and other parameters. See the parameters that I use below:

"\\cab-clstr_public_server\PUBLIC\Tools\SysInternals\BgInfo\wsinfo.bgi /TIMER:0"

The bgi file stores the configuration of what you want to collect from each workstation. Visit here to get more details on the capabilities of the bginfo utility.



The app object is associated to all workstations in the branch. I have also found that, for some reason, you need to include the user groups as well, but remove all checks for the object as shown. I have not yet determined why this is necessary.



I created a macro to point to the location of the tool on my network.



I then added the necessary file rights for the app object.


Ulrich Frei

To record this data on user login, we created a dummy simple Application with the name "Report".

  • No executable.
  • Distribution options | Options "Distribute always"
  • Association: all users with "force run"

Activate Reporting for this Application under Common | Reporting

  • We use "Distribution success" and "Log To File".
  • Set up a directory for the logfile. Give -WC-M-- Rights.
  • Filename "Report.csv"

On each user login, an entry in the report file is created with the following data:

  • Date and Time
  • Full name of the user
  • Full name of the Workstation
  • IP-Address
  • and some Details of the App.Object

(Not recorded is the MAC-Address)

You can view the report file with Excel.

I hope this helps.

Scott McKenna

Here's a simple option. Create a batch file that simply does:

IPCONFIG (or IPCONFIG/ALL) >> C:\IP.LOG (OR where you wish to put the file)

This command will create a text file wherever you want to write it that will record the IPCONFIG command information.

Wray Hutton

Here is a vbscript program that we use to log user access to our NetWare server this is called from the login script, Note, that we set the environment variable 'U' to the netware full_name field . We have a CRON dameon running that cycles and archives the log each month to keep the log file from growing to large. Feel free use and modify to suit your needs. (sorry for any wrapping of the text by the e-mail client)

-----------start------------------
'******************* NETWARE USER ACCESS LOGGER ******************************************************
'Log successful netware login, Usage: nwlog [filepath] 
' ARGUMENT filepath EXPECTED, but if not specified results saved .\PROGRAM_name.out
'
'Fields Logged:
'date stamp, windows account; netware id; netware fullname, computer hostname, [computer OS,cpu type, ram] IP-MAC addresses.
'2006 2 1,08:08:01,grad ,jdoe ,Jane Doe ,PSY-LAB-DES-6 , 131.104.216.175, 00-07-E9-AC-35-62
'
'Environment Variables (note:  Netware Login script must set one of them)
'USERNAME    <<account local
'NWUSERNAME    
'COMPUTERNAME <<Host name  will normally identify a room and bldg
'U        <<set by netware login script to Netware full_name field
'locale     <<dept special field env variable set to identify an area
'NUMBER_OF_PROCESSORS
'OS
'****************** (c)2006 Wray Hutton : Feel free to use and modify this script ************************
On Error Resume Next
 
Const ForAppending = 8
 
Dim strComputer
Dim objWMIService, objItem
Dim propValue
Dim SWBemlocator
Dim cItems
 

Dim objFileSystem, objOutputFile
Dim strOutputFile
Dim strReportLine
Dim strArg1
 

strReportLine =  Year(Now)&" "&Month(now)&" "&Day(Now)&", "&Hour(Now) &":"& minute(Now) &":"& Second(Now) &"  ,"
 
 ' Create a new FileSystemObject 
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
 
strArg1 = Wscript.Arguments.Item(0)
 
' generate a filename base on the script name, Replace if command line argument
strOutputFile = "./" & Split(WScript.ScriptName, ".")(0) & ".out"
if strArg1 = "" Then
 'WScript.Echo "NO ARGS"
 'create file if exist overwrite
  Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
 Else
 'WScript.Echo "ARG1="& strArg1
  if strArg1 ="-?" or strArg1="/?" then
   WScript.Echo WScript.ScriptName & VBCRLF & "Usage: " & Split(WScript.ScriptName, ".")(0)  & " [LogFilePath]" & VBCRLF & "With No Argument specified results are saved in : " & strOutputFile & VBCRLF & "With LogFilePath specified results are appended to the file."
   WScript.Quit(0)
  Else
   strOutputFile = strArg1
   'if exist open, else create, append to end of file
   Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, ForAppending, TRUE)
  End if
 End if
 
 
'---- get environment variables, append to string
Set shell= CreateObject("Wscript.Shell")
Set env = shell.Environment("process")
strReportLine = strReportLine & "usr:"& env("USERNAME") & ",nwid:" & env("NWUSERNAME") & ",nwfullname:" & env("U") & ",host:" & env("COMPUTERNAME") & ","
  
'---- get hardware/os specific information such as cpu, number processors, OS
  
  
'---- get ip addresses and mac address of available NIC's 
strComputer = "."
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set cItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
For Each objItem in cItems
 
 For Each propValue in objItem.IPAddress
  MyIP = objItem.IPAddress(0)
  MyMac= objItem.MACAddress(0)
  strReportLine = strReportLine & " IPMAC:"&MyIP&","&MyMac&","
  
 ' objOutputFile.WriteLine(MyIP&","&MyMac&",")  
 ' Console.WriteLine(MyIP&","&MyMac)
 ' Wscript.WriteLine(MyIP&","&MyMac)
 ' WScript.Echo "IPAddress: " &  MyIP & "MACaddress  " &MyMac
 
 Next
 
Next
 
objOutputFile.WriteLine(strReportLine)
objOutputFile.Close
 
Set objFileSystem = Nothing
 
----------end----------

Michael Alexander

SysInternals has a free utility called "hostname." You pass it a hostname and it will return the IP address (or pass an IP address and it returns the hostname).

If you are using a batch file, something like the following will give you username, computername and IP address.

Echo %username% > test.txt
Echo %computername% >> test.txt
hostname.exe %computername% >> test.txt

Alternatively you could use the output from ipconfig and pass that into your file, that would also list any additional network adapters in the computer that may not be the primary IP, but could potentially be used to make a connection inside the network.

The network_address variable mentioned before for setting an environment variable will also work well if you don't mind the IP address being in Hex.

In the login script:
Set netaddr="%NETWORK_ADDRESS"

In your script:
Echo %netaddr% >> textfile.txt (append to the text file)

172.20.1.80 would show up as: AC140150

We use:
Set netaddr="%NETWORK_ADDRESS">>4

To get the subnet the user logs into, then we control which ZENworks apps get deployed. We have separate apps for each facility, and have the app object distribution rules check the environment variable for the location.

Jules Kremer

I'm using an script that fills environment settings during the container loginscript:

SET USER=LOGIN_NAME
SET IPNUMMER=NETWORK_ADDRESS
SET HWADRES=P_STATION
SET USERFULLNAME=FULL_NAME
SET UUR=HOUR24
SET MINUUT=MINUTE
SET DAG=DAY
SET MAAND=MONTH_NAME
SET JAAR=YEAR
SET MSINFO=MESSAGE_SERVER
DOS SET LOCATIE="DFT"
And during the startup of ZENworks I call a batchfile that appends this data to a textfile on the network. A coworker wrote a tool to convert the hex addres to xx.xx.xx.xx format based on the textfile and it creates a csv file, ready to import into excel. Works in a IP only environment.

Michael Alexander

SysInternals has a free utility called "hostname." You pass it a hostname and it will return the IP address (or pass an IP address and it returns the hostname).

If you are using a batch file, something like the following will give you username, computer name and IP address:

Echo %username% > test.txt
Echo %computername% >> test.txt
hostname.exe %computername% >> test.txt

Alternatively you could use the output from ipconfig and pass that into your file, that would also list any additional network adapters in the computer that may not be the primary IP, but could potentially be used to make a connection inside the network.

The network_address variable mentioned before for setting an environment variable will also work well if you don't mind the IP address being in Hex.

In the login script:
Set netaddr="%NETWORK_ADDRESS"

In your script:
Echo %netaddr% >> textfile.txt (append to the text file)

172.20.1.80 would show up as: AC140150

We use:
Set netaddr="%NETWORK_ADDRESS">>4

To get the subnet the user logs into, then we control which ZENworks apps get deployed. We have separate apps for each facility, and have the app object distribution rules check the environment variable for the location.

Stephanos Kotsakis

Here is my solution to this IP Address problem.

  • pros: low impact on users/workstations
  • cons: only supports 2000/xp/2003 clients

The key to this solution is hexadecimal arithmetic that is native to the Microsoft command shell. The general idea is to record the %NETWORK_ADDRESS field into an environment variable and then convert each octet to its decimal value.

  1. Export the Novell login script variable to the users environment:

    set iphex="%NETWORK_ADDRESS"
  2. compute the decimal octets and concatenate them into the IP address of the user, use setx to make the ipaddress variable permanent.

    #cmd /v:on /c "set /a octet1=0x%iphex:~0,2% && set /a octet2=0x%iphex:~2,2% && set /a
    octet3=0x%iphex:4,2% && set /a octet4=0x%iphex:6,2% && setx ipaddress !octet1!.!octet2!.!octet3!.!octet4!"
    This step will calculate the decimal values for each octet in the NETWORK_ADDRESS variable and store them temporarily in the environment. Then the setx command runs and builds the ipaddress string and sets it as a global user variable.

Enjoy!


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell