Avatar of tbkurtz
tbkurtzFlag for United States of America

asked on 

Variables and Batch Files - Assign nslookup to a Variable

Alright,

Here's what I'd like to do...

First, ask the user for input, a computer name.  Then take the computer name and look up the IP address.  I'd then like to assign the IP address to a variable so that I can use it to pass to a outside program.

Attached is what I have so far- I have run into an issue, the output for nslookup have more information then just the IP address- and I am also unsure of how to assign the output on line 3 to a new variable.
@ECHO OFF
set /p computerName= Please enter users computer name: 
nslookup %computerName%
pause

Open in new window

Windows BatchVB Script

Avatar of undefined
Last Comment
knightEknight
Avatar of tbkurtz
tbkurtz
Flag of United States of America image

ASKER

Here's more specific on what I'm doing.
@ECHO OFF
set /p computerName= Please enter users computer name: 
nslookup %computerName%
REM Need to set a variable to the IP %computerIP%
set /p disableKey= Would you like to disable User Permission? Y/N :
if /i %disableKey==Y cscript script.vbs %computerName%
C:\FOLDER\sub\sub\executable.exe 2 %computerIP%
pause
if /i %disableKey==Y cscript script2.vbs %computerName%

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of knightEknight
knightEknight
Flag of United States of America image


for /f "tokens=1-3" %%X in ('ping -n 1 %computerName%
 ^| find "Reply"') do set ip_addr=%%Z

set ip_addr=%ip_addr::=%

@echo %ip_addr%
Avatar of knightEknight
knightEknight
Flag of United States of America image

:oops, don't know what happened, but that first one is supposed to be all on one line...


for /f "tokens=1-3" %%X in ('ping -n 1 %computerName% ^| find "Reply"') do set ip_addr=%%Z

set ip_addr=%ip_addr::=%

@echo %ip_addr%
VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

39K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo