Solved

resolve hostnames to IPs

Posted on 2014-11-07
11
79 Views
Last Modified: 2015-01-13
I would like to resolve a list of hostnames to IP addresses. How do I accomplish that?
0
Comment
Question by:totoroha
  • 4
  • 4
  • 2
  • +1
11 Comments
 

Author Comment

by:totoroha
ID: 40429708
I would like to resolve a list of hostnames to IP addresses. How do I accomplish that?
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 40429711
In bash or python (you posted in both zones)
0
 
LVL 13

Accepted Solution

by:
Rizzle earned 250 total points
ID: 40429712
You can use something callef FastResolver.

http://www.nirsoft.net/utils/fastresolver.html
0
 

Author Comment

by:totoroha
ID: 40429724
I know about that tool, but I want to import a lists of websites, domain names and export it to a txt file with the ip address.
I don't mind if you can help me with both bash and python.

Thank you so much.
0
 
LVL 28

Assisted Solution

by:becraig
becraig earned 250 total points
ID: 40429738
Here is a good example:
import socket
hostname = 'maps.google.com'
addr = socket.gethostbyname(hostname)
print 'The address of ', hostname, 'is', addr 

Open in new window


http://codedrop.blogspot.com/2011/02/turning-hostname-into-ip-address.html
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 32

Expert Comment

by:DrDamnit
ID: 40429739
BASH is probably easiest to get the information, and then you can wrap a python loop around it rather easily, and use Python to write it to a file.

So, we need to be able to execute a python script that will run this bash command to get the IPs.

The first thing we're going to use is a group of tools piped together:

dig
grep
awk

Dig gets the records.
Grep filters the results to give us only lines with IPs
awk returns only the column that contains IPs:

Here's your command:
dig google.com | grep -P '([0-9]{1,}\.){3}' | awk '{print $5}'

Open in new window


Now, the first thing you'l notice here is that we are getting a list of A records for the domain. What do you want to do with the rollovers?
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 40429740
@becraig: does that get all hostname IPs?
0
 

Author Comment

by:totoroha
ID: 40429776
I think with becraig code, we have to put in the host name one by one. But if I put a variable there, replace it with the value from the imported text file, we can have the list of ip addresses. Is that correct Michael?
0
 

Author Comment

by:totoroha
ID: 40436220
can anyone help me with this?
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 40439020
Sorry... been taken away by personal matters.

His chide dies not require you enter Simon's one at a time. Like what I have you, it requires you build a loop with values (list of domain names) out pull then from other source like a database.

What level of programming expertise do you have? Are you comfortable building loops?
0
 
LVL 28

Expert Comment

by:becraig
ID: 40468876
Hi totoroha you can simply loop this through the hostnames from an input.

Some reading material
http://www.java2s.com/Code/Python/File/Loopthroughafile.htm
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now