PC Review


Reply
Thread Tools Rate Thread

Command to get computere name

 
 
Gerald
Guest
Posts: n/a
 
      19th Jul 2004
Is there a does command to get a computer name using its
IP address?
 
Reply With Quote
 
 
 
 
Jerold Schulman
Guest
Posts: n/a
 
      19th Jul 2004
On Mon, 19 Jul 2004 09:08:19 -0700, "Gerald"
<(E-Mail Removed)> wrote:

>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%

Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Reply With Quote
 
Gerald
Guest
Posts: n/a
 
      19th Jul 2004
Thanks, I will give it a shot

>-----Original Message-----
>On Mon, 19 Jul 2004 09:08:19 -0700, "Gerald"
><(E-Mail Removed)> wrote:
>
>>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%
>
>Jerold Schulman
>Windows: General MVP
>JSI, Inc.
>http://www.jsiinc.com
>.
>

 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      19th Jul 2004
Jerold Schulman wrote:

>On Mon, 19 Jul 2004 09:08:19 -0700, "Gerald"
><(E-Mail Removed)> wrote:
>
>>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,
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.

--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
 
Reply With Quote
 
Jerold Schulman
Guest
Posts: n/a
 
      19th Jul 2004

Thank you.

The following also works:
for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%^|findstr /i /L /C:"[%1]"') do (


On Mon, 19 Jul 2004 19:38:08 +0200, "Matthias Tacke" <(E-Mail Removed)>
wrote:

>Jerold Schulman wrote:
>
>>On Mon, 19 Jul 2004 09:08:19 -0700, "Gerald"
>><(E-Mail Removed)> wrote:
>>
>>>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,
>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
 
Reply With Quote
 
Gerald
Guest
Posts: n/a
 
      19th Jul 2004
Thanks again guys.


>-----Original Message-----
>
>Thank you.
>
>The following also works:
>for /f "Tokens=2" %%n in ('ping -a -n 1 %ip%

^|findstr /i /L /C:"[%1]"') do (
>
>
>On Mon, 19 Jul 2004 19:38:08 +0200, "Matthias Tacke"

<(E-Mail Removed)>
>wrote:
>
>>Jerold Schulman wrote:
>>
>>>On Mon, 19 Jul 2004 09:08:19 -0700, "Gerald"
>>><(E-Mail Removed)> wrote:
>>>
>>>>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,
>>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
>.
>

 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      20th Jul 2004
Jerold Schulman wrote:
>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 the
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 (

--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
 
Reply With Quote
 
Jerold Schulman
Guest
Posts: n/a
 
      20th Jul 2004
On Tue, 20 Jul 2004 11:45:59 +0200, "Matthias Tacke" <(E-Mail Removed)>
wrote:

>Jerold Schulman wrote:
>>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 the
>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 (


Yes. My revised script:

@echo off
if {%2}=={} @echo Syntax IPName IP Name [/f]&goto :EOF
set %2=NF
if not {%3}=={} if /i {%3} NEQ {/F} @echo Syntax IPName IP Name [/f]&goto :EOF
for /f "Tokens=2" %%n in ('ping -a -n 1 %1^|findstr /L /C:"[" /C:"]"') do (
set %2=%%n
)
if /i {%3} EQU {/F} goto :EOF
for /f "Tokens=1 Delims=. " %%n in ('@echo %%%2%%') do (
set %2=%%n
)

Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute Batch Command Automatically form Command Shell with Minlogon stuie_norris@yahoo.com.au Windows XP Embedded 1 21st May 2010 12:26 PM
Data shape command text contains a syntax error at or near position 106 in the command. Bob Microsoft Access ADP SQL Server 3 14th Apr 2008 09:43 PM
Pivot Table Error Message - "Command Text not set for command obje =?Utf-8?B?SmVmZiBEaXZpYW4=?= Microsoft Excel Misc 0 7th Nov 2007 10:26 PM
autorun.inf - shell\..\command with command line parameter doesn'twork kakii Windows XP Help 1 17th May 2007 08:54 PM
A resource kit command that allows the NET USER command to get info strictly from a specific container or OU =?Utf-8?B?Ym9vNzc3?= Microsoft Windows 2000 Active Directory 3 11th May 2004 08:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:51 PM.