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

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

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

Get Remote IP Addresses and Usernames to a List


Question:

How can i get ip adress of all my users in my domain,and then that winbatch will write all the d etails of every single user+his ip address to "list.txt" file so i will can read from this file what his ip and who(user) use this ip ?

Answer:

If you have admin access to the machine and can do a RegConnect to it, you can query the remote registry for the username and ipaddress.
AddExtender("WWWNT34I.DLL")

;Specify file to write to
handle = FileOpen("c:\iplist.txt","WRITE")

servers = wntServerList("","",4096)
count = ItemCount(servers,@tab)
For x = 1 to count
   line = ""
	remoteMachine= ItemExtract(x,servers,@tab)
	
	;Connect to remote machines registry (must have necessary permissions)
	ErrorMode(@off)
	regRemoteMachine=RegConnect(remotemachine, @REGMACHINE)
	ErrorMode(@cancel)
	if regRemoteMachine==0
		 line = StrCat("Error connecting to ",remoteMachine,@tab,IntControl (34, LastError(), 0, 0, 0))
		 FileWrite(handle,line)
		 continue
	endif
	
	;Get username
	ErrorMode(@off)
	key=RegOpenkey(regRemoteMachine, "Software\Microsoft\Windows NT\CurrentVersion\Winlogon")
	ErrorMode(@cancel)
	if key==0
		 line = StrCat("Error connecting to ",remoteMachine,@tab,IntControl (34, LastError(), 0, 0, 0))
		 FileWrite(handle,line)
		 continue
	endif
	username=RegQueryValue(Key,"[DefaultUserName]")
	RegCloseKey(key)
		
	;Get netadapter
	ErrorMode(@off)
	key=RegOpenkey(regRemoteMachine, "Software\Microsoft\Windows NT\CurrentVersion\NetworkCards")
	ErrorMode(@cancel)
	if key==0
		 line = StrCat("Error connecting to ",remoteMachine,@tab,IntControl (34, LastError(), 0, 0, 0))
		 FileWrite(handle,line)
		 continue
	endif
	NxtAdapter=RegQueryKey(key,0)
	NetAdapter=RegQueryValue(Key,StrCat(NxtAdapter,"\[ServiceName]"))
	RegCloseKey(key)
	
	;Get ipaddress defaultgateway and subnetmask.
	ErrorMode(@off)
	Key=RegOpenKey(regRemoteMachine, StrCat("System\CurrentControlSet\Services\",NetAdapter))
	ErrorMode(@cancel)
	if Key==0
		 line = StrCat("Error connecting to ",remoteMachine,@tab,IntControl (34, LastError(), 0, 0, 0))
		 FileWrite(handle,line)
		 continue
	endif
	ipaddr = RegQueryMulSz(Key,"Parameters\tcpip\[IPAddress]"," ")
	defgateway = RegQueryMulSz(Key,"Parameters\tcpip\[DefaultGateway]"," ")
	subnetmask = RegQueryMulSz(Key,"Parameters\tcpip\[SubnetMask]"," ")
	RegCloseKey(key)
	RegCloseKey(regRemoteMachine)
	
	;Display results
	line = StrCat(remoteMachine,@tab,"Username: ",username,@tab, "IPAddress: ",ipaddr,@tab,"DefaultGateway: ",defgateway,@tab,"SubnetMask: ",subnetmask) 

	FileWrite(handle,line)
next
FileClose(handle)
exit

Article ID:   W15979
File Created: 2004:03:30:15:42:06
Last Updated: 2004:03:30:15:42:06