1

I need to figure out how to solely display the IP Address of a computer for my batch file. I don't want the one where it displays IP Address ................."%IP Address%

I need it to say something similar to this.

set time=&time/t set computername=%computername% set IP=%IP Address% echo. echo. echo. %time% %computername% %IP Address% 

so if my time was 9:13PM my computername is tracckkk1 and my IP Address was 14.14.14.14 then it would say

9:13PM tracckkk1 14.14.14.14

and not

21:13:51 tracckkk1 IP Address.. ...............14.14.14.14

thanks to anyone that is answering this question!

3
  • Sorry if this is a silly question, I would just like to clarify one thing. When you said, ‘I don't want the one where it displays IP Address ................."%IP Address%’, did you mean that you don't want the IP address to be formatted like that or that you want a different IP address (not from that line)? Also, is the line supposed to come from ipconfig? Commented Feb 10, 2013 at 3:38
  • i dont want the ip address to display that line i want it to only show my ip address so i believe that the answer to your question would be i want it to be formatted differently Commented Feb 10, 2013 at 5:23
  • possible duplicate of How do I get the IP address into a batch-file variable? Commented Feb 11, 2013 at 0:57

2 Answers 2

4

Following will work

 @echo off setlocal enabledelayedexpansion set /p hostname=Enter hostname: for /f "tokens=3" %%a in ('ping -4 %hostname% ^| find "Pinging"') do ( set ip=%%a set ip=!ip:[=! set ip=!ip:]=! echo %date% %computername% !ip! ) 
Sign up to request clarification or add additional context in comments.

1 Comment

i would uprate you but im not at lvl 15 yet. Sorry ill do it once i do though
0

The following will capture the IP address of the computer in an environment variable named IP_ADDRESS.

(Note: the value of IP_ADDRESS will have a leading space.)

for /f "usebackq delims=: tokens=2" %%i in (`ipconfig ^| findstr Address`) do ( set IP_ADDRESS=%%i ) 

Here is documentation for the For keyword.

Update: There may be problems with this approach. See this question.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.