networking-forum.com
Community BlogCommunity Wiki * Register  * Search  * Login
View unanswered postsView active topics

All times are UTC - 6 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jun 06, 2012 1:38 pm 
Offline
New Member
New Member

Joined: Fri Jun 01, 2012 1:39 pm
Posts: 5
Hey all,

I am trying to do a reverse DNS lookup (ip to hostname) on a list of IP's that I have in a txt file. There are ~460 addresses so I would obviously prefer not doing this manually. :lol:

After much googling, I have come up with this.

$listofIPs = Get-Content c:\iplist.txt

foreach($i in $listofips)
{
try
{
$ip = $i
$HostName = [System.Net.Dns]::GetHostByAddress($ip).HostName
Test-Connection $HostName -Count 1
}
catch
{
Write-Warning "Cannot resolve $ip"
continue
}
}

The command seems to execute but I get a "WARNING: Cannot resolve (IP Address)" error for every IP address that is in my file. It seems to parse the addresses correctly and when I use the

$IP = “(IP Address)”

[System.Net.Dns]::GetHostEntry($IP)

command, it resolves the IP just fine.

I am a complete n00b when it comes to PS and this is probably a super easy fix, but I need help! Thanks ahead of time!


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 2:14 pm 
Offline
Senior Member
Senior Member

Joined: Wed Dec 29, 2010 1:01 pm
Posts: 485
Location: New York
Certs: CCNA
What does the iplist.txt file look like? Is it just IP addresses? The scripts works well for me (I removed Test-Connection) and created an iplist.txt file:

Code:
4.1.1.1
4.2.2.2


Which outputs:

Code:
4.1.1.1
vnsc-bak.sys.gtei.net


I tried with both [System.Net.Dns]::Resolve($ip) as well as [System.Net.Dns]::GetHostByAddress($ip)

_________________
I don't have a signature.


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 3:02 pm 
Offline
New Member
New Member

Joined: Fri Jun 01, 2012 1:39 pm
Posts: 5
I have tried various masks for my txt file. Right now, it is just

x.x.x.x
x.x.x.x
x.x.x.x

I have also tried

"x.x.x.x"
"x.x.x.x"

as well as

"x.x.x.x",
"x.x.x.x",


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 3:59 pm 
Offline
Senior Member
Senior Member

Joined: Wed Dec 29, 2010 1:01 pm
Posts: 485
Location: New York
Certs: CCNA
Sounds like something in that file is off....what app are you using to edit the file? Notepad, word, other? And it is just one ip per line and nothing else?

_________________
I don't have a signature.


Top
 Profile  
 
PostPosted: Thu Jun 07, 2012 1:12 pm 
Offline
New Member
New Member

Joined: Fri Jun 01, 2012 1:39 pm
Posts: 5
Yes, I figured out what the problem was. Jacksonh was right. When I copied the addresses out of excel into notepad, the editor I was using to answer your question, it appended a space to all of the addresses. I did a replace all on all of the spaces and copied it back into the file, then it worked just fine.

Thanks for all of your help guys.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group