user2605194
user2605194

Reputation:

batch list net view and write their ip address to a variable

I basically need a script (batch) that automatically converts the users on the local network to IP addresses. What I mean is basically set every user that shows up in the command "net view" to a different variable, for example:

If I had 4 different users on the network, I would need the file to list:

1: (%1%)
2: (%2%)
3: (%3%)
4: (%4%)

So I need the script to set each user on the network to a different variable (starting at 1)

Also...

How would I set the local IP address of each computer name as a variable?

update for second part: I need to know how to set the ip address as a variable. I just need to cut out the excess stuff. If I type

 ping (computername) -4

I get: well, I guess it is just easier to show you...

using ping

I think I need to use the findstr command, but I don't know.

Upvotes: 1

Views: 1479

Answers (1)

Matt Williamson
Matt Williamson

Reputation: 7095

Is this what you're looking for?

@echo off
setlocal enabledelayedexpansion

for /f "tokens=1" %%a in ('net view') do (
  set comp=%%a & set comp=!comp:\\=!
  for /f "tokens=2 delims=[]" %%b in (
    'ping -4 !comp!'
  ) do (Echo !comp! - %%b)
)

Upvotes: 1

Related Questions