Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get the FQDN of a list of IP servers?

Posted on 2011-02-10
8
Medium Priority
?
1,810 Views
Last Modified: 2012-06-22
Is there a script which can give the FQDN of servers from a file that contains their IP adr?
0
Comment
Question by:SAM2009
  • 5
  • 3
8 Comments
 
LVL 7

Expert Comment

by:SterlingMcClung
ID: 34868408
something like this should work
For /f %L in (file-with-ip-addresses.txt) do ping -a %L

Open in new window

0
 
LVL 7

Expert Comment

by:SterlingMcClung
ID: 34868436
Combine that with some unxutils and you can do:

 
for /f %L in (temp.txt) do @ping -a -n 1 %L | head -n2 | tail -n1 | cut -d" " -f2,3

Open in new window


Hope that works.
0
 
LVL 1

Author Comment

by:SAM2009
ID: 34873637
Is it in vbs?
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
LVL 7

Expert Comment

by:SterlingMcClung
ID: 34879763
Sorry, no.  This is just a command line.  Run it from a command prompt or place in it a .bat/.cmd file.
0
 
LVL 7

Expert Comment

by:SterlingMcClung
ID: 34880614
The head, tail and cut commands are not built into windows, but are very useful tools from Unix.  Many of these useful programs have been ported to native Windows applications in the unxutils project at sourceforge.  You can obtain them from:

http://unxutils.sourceforge.net/

I tend to put these in a bin folder in my C:\ on all of my computers and add the directory to the systemwide Path variable.  They are very useful in solving problems like this.
0
 
LVL 1

Author Comment

by:SAM2009
ID: 34903862
With that cmd NS LOOKUP ZONE should be added in DNS right to get a result?
0
 
LVL 7

Accepted Solution

by:
SterlingMcClung earned 2000 total points
ID: 34910409
I am not sure what you are referring to.  I will describe what each part of the command does and then if you still have more questions, please ask away.

The first part of the command:
 
for /f %L in (temp.txt) do

Open in new window

Reads each line of the temp.txt file, on at a time, places the contents of that line in the %L variable and executes the command after "do" for each line it reads.  As psuedo-code:
 
For each line in temp.txt
   do 
Next

Open in new window


The file "temp.txt" must have a single IP address for which you want the FQDN on each line of the file.

Next portion of the command:
 
@ping -a -n 1 %L

Open in new window

The "@" symbol at the beginning tells the command processor to not echo the command line.  This is done just to keep things looking nice.  The "-a" parameter for ping, tells ping to perform a reverse DNS lookup on the address.  This is what gives you the FQDN of the IP address.  The "-n1" parameter tells it to just send one echo request instead of the default 4.  This is just to speed of the process.  The "%L" is the contents of the temp.txt line read on this iteration of the command.  Ping will use the DNS servers that are listed with the network adapters of the computer.  If you have multiple network adapters, you can add a "-S sourceaddr" parameter to the command in order to specify which network card and DNS settings to use.  If you would like to use a different DNS server than is listed in your adapter settings, this script will not work.

The results of the ping command are piped to:
 
| head -n2 | tail -n1 |

Open in new window

Which take the first 2 lines of text, then only the last line of those lines, or in other words take the second line and pipe it to the next command:
 
cut -d" " -f2,3

Open in new window

which tells it to split the text with a space character as the delimiter and then return only the second and third fields.

As I mentioned partway through this post, the DNS servers that you wish to use to obtain the FQDN must be listed in your network adapters DNS settings.  As long as the domains are public domains and not an internal domain, such as domain.local, it shouldn't matter which DNS servers are used to obtain the FQDN, as they should all provide the same name.  Some DNS services, like opendns and some ISPs, filter and modify DNS requests and answers in order to block access to what they feel are bad sites or destinations.  If you would like to run this for an internal domain, you will have to have the internal DNS server setup in the adpater settings.
0
 
LVL 1

Author Closing Comment

by:SAM2009
ID: 34913276
Thank you for the explanation and help!
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question