IP address - Hostname

  • 54 Views
  • Last Post 22 June 2015
anandh11.v posted this 22 June 2015

Hello Folks,
Is there a command or scripts which could be used for retrieving the Hostnames using the IP addresses.
I have tried few commandlets available in MS site however I didn't get the end result as expected.
If any one of have something please do share 
ThanksAnand

Order By: Standard | Newest | Votes
PARRIS posted this 22 June 2015

Ping –a xx.xx.xx.xx Regards, Mark ParrisActive Directory ConsultantMobile: +44 7801 690596E-mail:mark@xxxxxxxxxxxxxxxx  MVP Directory Services | MCM Directory Services

show

benwayj posted this 22 June 2015

Do you mean like

 

Ping –a 192.168.1.10



 

Is that what you are looking for ? just replace 192.168.1.10 with the IP you’re looking for the hostname

 

show

dsolodow posted this 22 June 2015

Ping –a?

 

DAMIEN SOLODOW

Senior Systems Engineer

317.447.6033 (office)

317.447.6014 (fax)

HARRISON COLLEGE

 

show

Mahdi.Tehrani posted this 22 June 2015

If you have reverse look up zone configured you can try ping -a‎ command.








Sent from my BlackBerry 10 smartphone.















show







Hello Folks,




Is there a command or scripts which could be used for retrieving the Hostnames using the IP addresses.




I have tried few commandlets available in MS site however I didn't get the end result as expected.




If any one of have something please do share 










Thanks

Anand 

webster posted this 22 June 2015

Michael B. Smith has me use this in my scripts where a computername parameter can be entered as an IP address (among other ways).

 

Function TestComputerName

{

                Param([string] $CName)              



 

                #several tests for $cname as an actual name

 

                #if not a name, see if IP address

                $ip = $CName -as [System.Net.IpAddress]

                If($ip)

                {

                                $Result = [System.Net.Dns]::gethostentry($ip)}

                               



                                If($? –and $Results –ne $Null)

{

                                                #do other tests now that we have the dns hostname

}

                }

 

 

Thanks

 

 

Webster

 

show

anandh11.v posted this 22 June 2015

I was using the following power shell command to retrieve the information since I have close 200+ ip's whose Hostnames need to be found. The command displays the Hostnames however exporting it only writes the numberGet-Content C:\IPAddress.txt | ForEach-Object {([system.net.dns]::GetHostByAddress($)).hostname >> c:\hostname.txtThanks A
On Monday 22 June 2015, Webster <webster@xxxxxxxxxxxxxxxx> wrote:
















Michael B. Smith has me use this in my scripts where a computername parameter can be entered as an IP address (among other ways).

 

Function TestComputerName

{

                Param([string] $CName)              



 

                #several tests for $cname as an actual name

 

                #if not a name, see if IP address

                $ip = $CName -as [System.Net.IpAddress]

                If($ip)

                {

                                $Result = [System.Net.Dns]::gethostentry($ip)}

                               



                                If($? –and $Results –ne $Null)

{

                                                #do other tests now that we have the dns hostname

}

                }

 

 

Thanks

 

 

Webster

 

show

Douglast posted this 22 June 2015











How about nslookup?

 

show

anandh11.v posted this 22 June 2015

nslookup would work but I have to use individual IP's.
On Monday 22 June 2015, Douglas Tirevold <DTirevold@xxxxxxxxxxxxxxxx> wrote:














How about nslookup?

show

PARRIS posted this 22 June 2015

This is a very basic script @echo offdel log.txt 2>nulfor /f "delims=" %%a in (pinglist.txt) do ping -n 1 -a %%a >>log.txt Create a textfile called pinglist.txt and away you go. Output looks like this, which you can munge in Excel. Pinging server.markparris.net [10.20.30.40] with 32 bytes of data:Reply from 10.20.30.40: bytes=32 time<1ms TTL=128 Ping statistics for 10.20.30.40:    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:    Minimum = 0ms, Maximum = 0ms, Average = 0ms   Regards, Mark ParrisActive Directory ConsultantMobile: +44 7801 690596E-mail:mark@xxxxxxxxxxxxxxxx   MVP Directory Services | MCM Directory Services

show

anandh11.v posted this 22 June 2015

I was try a different power shell commandlet 
Get-Content C:\IPAddress.txt | ForEach-Object {([system.net.dns]::GetHostByAddress($)).hostname >> c:\hostname.txt

On Monday 22 June 2015, Mark Parris <mark@xxxxxxxxxxxxxxxx> wrote:
















This is a very basic script



 

@echo off

del log.txt 2>nul

for /f "delims=" %%a in (pinglist.txt) do ping -n 1 -a %%a >>log.txt

 

Create a textfile called pinglist.txt and away you go.

 

Output looks like this, which you can munge in Excel.

 

Pinging server.markparris.net [10.20.30.40] with 32 bytes of data:

Reply from 10.20.30.40: bytes=32 time<1ms TTL=128

 

Ping statistics for 10.20.30.40:

    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

    Minimum = 0ms, Maximum = 0ms, Average = 0ms

 

 

 

Regards,

 

Mark Parris

Active Directory Consultant

Mobile: +44 7801 690596



E-mail:

mark@xxxxxxxxxxxxxxxx 

 



MVP Directory Services | MCM Directory Services


Twitter |

Blog |

LinkedIn
| Skype |

About.me



 

show

webster posted this 22 June 2015

This works for me:

 

$ips = get-content IPAddress.txt

ForEach($ip in $ips)

{

     $IPAddress = $ip -as [System.Net.IpAddress]

     If($IPAddress)

     {

           $Result = [System.Net.Dns]::GetHostEntry($IPAddress)

           If($? -and $Result -ne $Null)

           {

                $Result.HostName | out-file hostname.txt -append -EA 0



           }



     }

}

 

Contents of hostname.txt:

 

labdc2.labaddomain.com

eDocsDC.LabADDomain.com

 

 

Thanks

 

 

Webster

 

show

Chris-Dent posted this 22 June 2015

Gotta have some PowerShell-isms in here ;)
This executes a reverse lookup using the built-in stub-resolver
[Net.Dns]::GetHostEntry("1.2.3.4")
There's, of course, always nslookup and dig, but there are few different PS-based DNS resolvers. MS have one built into 2012 (and Win 8, maybe 8.1).
I have two full debugging resolvers of my own (Get-Dns), as you do:
https://github.com/TeflonJim/Indented (Indented.DnsResolver)
https://dnsshell.codeplex.com/
There a few more of them around, including Joel's:
https://www.powershellgallery.com/packages/PoshNet/
Cheers!
Chris


show

PARRIS posted this 22 June 2015

This works too Get-Content C:\Scripts\Ping\pinglist.txt | ForEach-Object {([system.net.dns]::GetHostByAddress($)).hostname >> C:\Scripts\Ping\hostname.txt}    Regards, Mark ParrisActive Directory ConsultantMobile: +44 7801 690596E-mail:mark@xxxxxxxxxxxxxxxx   MVP Directory Services | MCM Directory Services

show

anandh11.v posted this 22 June 2015

Will the below script write the list of unresolved IP's
On Monday 22 June 2015, Webster <webster@xxxxxxxxxxxxxxxx> wrote:
















This works for me:

 

$ips = get-content IPAddress.txt

ForEach($ip in $ips)

{

     $IPAddress = $ip -as [System.Net.IpAddress]

     If($IPAddress)

     {

           $Result = [System.Net.Dns]::GetHostEntry($IPAddress)

           If($? -and $Result -ne $Null)

           {

                $Result.HostName | out-file hostname.txt -append -EA 0



           }



     }

}

 

Contents of hostname.txt:

 

labdc2.labaddomain.com

eDocsDC.LabADDomain.com

 

 

Thanks

 

 

Webster

 

show

kurtbuff posted this 22 June 2015

Powershell one-liner:
http://techibee.com/powershell/powershell-resolving-dns-namesname-to-ip-ip-to-name/1192
or
http://blogs.msdn.com/b/powershell/archive/2006/06/26/647318.aspx

And yes, as someone else pointed out, there needs to be a reverse zone
in your DNS for this to be useful.

Kurt

show

Close