G
Gerald
Is there a does command to get a computer name using its
IP address?
IP address?
Is there a does command to get a computer name using its
IP address?
^|findstr /i /c:"Pinging"') do (-----Original Message-----
Is there a does command to get a computer name using its
IP address?
I just scripted IPName.bat for you.
The syntax for using IPName is:
[call] IPName IPAddress Name [/f]
where IPAddress is the IP Address.
Name is a the environment variable name you want returned.
/f is optional and causes the fully qualified name to be returned.
IPName.bat contains:
@echo off
if {%2}=={} @echo Syntax IPName IP Name [/f]&goto :EOF
setlocal
set ip=%1
set Type=C
set Name=NF
if /i {%3}=={/F} set Type=D
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%
Hello Jerold,Jerold said:Is there a does command to get a computer name using its
IP address?
I just scripted IPName.bat for you.
The syntax for using IPName is:
[call] IPName IPAddress Name [/f]
where IPAddress is the IP Address.
Name is a the environment variable name you want returned.
/f is optional and causes the fully qualified name to be returned.
IPName.bat contains:
@echo off
if {%2}=={} @echo Syntax IPName IP Name [/f]&goto :EOF
setlocal
set ip=%1
set Type=C
set Name=NF
if /i {%3}=={/F} set Type=D
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%^|findstr /i /c:"Pinging"') do (
set Name=%%n
)
if "%Type%" NEQ "C" goto finish
for /f "Tokens=1 Delims=. " %%n in ('@echo %Name%') do (
set Name=%%n
)
:finish
endlocal&set %2=%Name%
Hello Jerold,Jerold said:Is there a does command to get a computer name using its
IP address?
I just scripted IPName.bat for you.
The syntax for using IPName is:
[call] IPName IPAddress Name [/f]
where IPAddress is the IP Address.
Name is a the environment variable name you want returned.
/f is optional and causes the fully qualified name to be returned.
IPName.bat contains:
@echo off
if {%2}=={} @echo Syntax IPName IP Name [/f]&goto :EOF
setlocal
set ip=%1
set Type=C
set Name=NF
if /i {%3}=={/F} set Type=D
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%^|findstr /i /c:"Pinging"') do (
set Name=%%n
)
if "%Type%" NEQ "C" goto finish
for /f "Tokens=1 Delims=. " %%n in ('@echo %Name%') do (
set Name=%%n
)
:finish
endlocal&set %2=%Name%
to be more locale independent I suggest a small modification. In my
locale it's only "Ping". But the ip name is followed by the ip number in
square brackets so :
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%^|findstr "\[%~1\]"') do (
should be more universal. Since fndstr is by default in regexp mode the
brackets have to be escaped, the dots from the ip number will be
interpreted as any char but that won't harm.
^|findstr /i /L /C:"[%1]"') do (-----Original Message-----
Thank you.
The following also works:
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%
Hello Jerold,Jerold said:On Mon, 19 Jul 2004 09:08:19 -0700, "Gerald"
Is there a does command to get a computer name using its
IP address?
I just scripted IPName.bat for you.
The syntax for using IPName is:
[call] IPName IPAddress Name [/f]
where IPAddress is the IP Address.
Name is a the environment variable name you want returned.
/f is optional and causes the fully qualified name to be returned.
IPName.bat contains:
@echo off
if {%2}=={} @echo Syntax IPName IP Name [/f]&goto :EOF
setlocal
set ip=%1
set Type=C
set Name=NF
if /i {%3}=={/F} set Type=D
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip% ^|findstr /i /c:"Pinging"') do (
set Name=%%n
)
if "%Type%" NEQ "C" goto finish
for /f "Tokens=1 Delims=. " %%n in ('@echo %Name%') do (
set Name=%%n
)
:finish
endlocal&set %2=%Name%
to be more locale independent I suggest a small modification. In my
locale it's only "Ping". But the ip name is followed by the ip number in
square brackets so :
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip% ^|findstr "\[%~1\]"') do (
should be more universal. Since fndstr is by default in regexp mode the
brackets have to be escaped, the dots from the ip number will be
interpreted as any char but that won't harm.
Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
.
That's right, and may be shortened further %1 contains a number, so theJerold said:Thank you.
The following also works:
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%^|findstr /i /L /C:"[%1]"') do (
That's right, and may be shortened further %1 contains a number, so theJerold said:Thank you.
The following also works:
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%^|findstr /i /L /C:"[%1]"') do (
ignore case /I can be omitted as the /L switch which resembles the /C:,
in this case even the qoutes are obsolete.
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%^|findstr /C:[%1]') do (