Parsing File For Domain Name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing File For Domain Name
# 1  
Old 11-27-2010
Parsing File For Domain Name

I was trying to setup some conficker monitoring for my network
I took the list from
Code:
http://www.epicwinrar.com/conficker/domains.txt

The text file format containing
Code:
Variant, Date, Index, Hostname
A, 10/01/2008, 0, kuwzclqpw.com
A, 10/01/2008, 1, hspch.net
A, 10/01/2008, 2, sumkuezgsq.info
A, 10/01/2008, 3, ibcct.net
.
upto 3500 lines
.
B, 06/30/2009, 245, themziwbvky.com
B, 06/30/2009, 246, dmwznbpiug.ws
B, 06/30/2009, 247, jdsjytlnlj.ws
B, 06/30/2009, 248, bbsle.com
B, 06/30/2009, 249, kbojbitigx.biz

I would like to resolve the hostname from domains.txt into ip address in ipaddress.txt to check wether the hostname is still active using
Code:
#!/bin/bash
#
# File: check_domains_conficker.sh
#
CONFICKER="domains.txt"
DNS="1.2.3.4"
cat $FILE | while read domain
do
  ip=`dig @$DNS +time=1 +short $CONFICKER`
  echo "$CONFICKER:$ip" >> ipaddress.txt
done

doesnt seems to work
Than I would grep only the ip address and take the most 50 resolved ip address with
Code:
grep -oe "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" \ ipaddress.txt | sort > ipaddress_exist

Code:
#!/bin/bash
# File: count_modulus_ip_conficker.sh
file=ipaddress_exist
i=0
oldip='Initialization'
while read newip
do
  if [ $newip == $oldip ]
  then
    i=$((i+1))
  else
    i=$((i+1))
    echo "$oldip: $i"
    i=0
    oldip=$newip
  fi
  done <$file
  echo "$oldip: $((i+1))"
done

please evaluate the script
much appreciated

Last edited by bEgUnDaL; 11-28-2010 at 04:16 AM..
# 2  
Old 11-28-2010
Code:
#!/bin/bash
#
# File: check_domains_conficker.sh
#
CONFICKER="domains.txt"
DNS="1.2.3.4"
awk '{print $NF}' $CONFICKER| while read domain
do
  ip=`dig @$DNS $domain +time=1 +short`
  echo "$CONFICKER:$ip" >> ipaddress.txt
done


Last edited by rdcwayx; 11-28-2010 at 04:42 AM..
# 3  
Old 11-28-2010
Quote:
Originally Posted by rdcwayx
Code:
#!/bin/bash
#
# File: check_domains_conficker.sh
#
CONFICKER="domains.txt"
DNS="1.2.3.4"
awk '{print $NF}' $CONFICKER| while read domain
do
  ip=`dig @$DNS $domain +time=1 +short`
  echo "$CONFICKER:$ip" >> ipaddress.txt
done

with that script the ipaddress.txt content is
Code:
domains_conficker.txt:
domains_conficker.txt:
domains_conficker.txt:

what I'm trying todo is having an output of
Code:
somedomain.tld:ip.ad.dr.ess
somedomain.tld:ip.ad.dr.ess
somedomain.tld:ip.ad.dr.ess

# 4  
Old 11-28-2010
Comment the top line of the domains.txt file containing column headers and try this:

Code:
 
#!/bin/bash
#
# File: check_domains_conficker.sh
#
CONFICKER="domains.txt"
DNS="1.2.3.4"
awk -F\, '!/^#/{print $4}' $CONFICKER| while read domain
do
  ip=`dig @$DNS $domain +time=1 +short`
  echo "$CONFICKER:$ip" >> ipaddress.txt
done


Last edited by ilikecows; 11-28-2010 at 05:51 AM.. Reason: added code tags
# 5  
Old 11-28-2010
Quote:
Originally Posted by ilikecows
Comment the top line of the domains.txt file containing column headers and try this:

Code:
 
#!/bin/bash
#
# File: check_domains_conficker.sh
#
CONFICKER="domains.txt"
DNS="1.2.3.4"
awk -F\, '!/^#/{print $4}' $CONFICKER| while read domain
do
  ip=`dig @$DNS $domain +time=1 +short`
  echo "$CONFICKER:$ip" >> ipaddress.txt
done

input domains.txt
Code:
A, 10/01/2008, 0, kuwzclqpw.com
A, 10/01/2008, 1, hspch.net

output ipaddress.txt
Code:
domains.txt:
domains.txt:


Last edited by bEgUnDaL; 11-28-2010 at 08:02 AM.. Reason: typo
# 6  
Old 11-28-2010
Code:
CONFICKER="domains.txt"
DNS="1.2.3.4"
awk -F\, '!/^#/{print $4}' $CONFICKER| while read domain
do
  ip=`dig @$DNS $domain +time=1 +short`
  echo "$domain:$ip" >> ipaddress.txt
done

Works on my machine. Try changing the $CONFICKER to $domain.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get only domain from url file bind

Hello everybody I have been trying to extract the domain name from the bind query log with different options, however always get stuck with domains that end with link .co.uk or .co.nz. I tried the following, however only provides the first level: awk -F"." '{print $(NF-1)"."$NF}' list.txt >... (30 Replies)
Discussion started by: omuhans123
30 Replies

2. Linux

Force file ownership of a domain user in samba Share

Hi, I am using RedHat 6 and ,I am trying to force a domain user (from Windows AD) to take ownership of a file when it is created, or copied on a Samba share. I have managed to get this working for the root user using the code below: COMMENT = IT Data Share path =... (2 Replies)
Discussion started by: p2bas
2 Replies

3. Ubuntu

Adding Domain name n resolv.conf file without vi editor

Hi Guys, I want to add the domain name entry to resolv.conf file. when i use the vi editor to do it the changes are gone after DNS client is being restarted. In Solairs 11 I figured out svccfg command will help to retain the cinfguration. but in linux how do we do that. Also for Solaris are there... (2 Replies)
Discussion started by: karthikk0508
2 Replies

4. Windows & DOS: Issues & Discussions

How to: Linux BOX in Windows Domain (w/out joining the domain)

Dear Expert, i have linux box that is running in the windows domain, BUT did not being a member of the domain. as I am not the System Administrator so I have no control on the server in the network, such as modify dns entry , add the linux box in AD and domain record and so on that relevant. ... (2 Replies)
Discussion started by: regmaster
2 Replies

5. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

6. Shell Programming and Scripting

extracting domain names out of a text file

I am needing to extract and list domain names out of a very large text file. The text file contains tlds .com .net .org and others as well as third level domains e.g. host1.domain.com and the names are placed within paragraphs of text. Domains do not have a http:// prefix so I'm thinking the... (6 Replies)
Discussion started by: totus
6 Replies

7. UNIX for Dummies Questions & Answers

Script for parsing details in a log file to a seperate file

Hi Experts, Im a new bee for scripting, I would ned to do the following via linux shell scripting, I have an application which throws a log file, on each action of a particular work with the application, as sson as the action is done, the log file would vanish or stops updating there, the... (2 Replies)
Discussion started by: pingnagan
2 Replies

8. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

9. UNIX for Dummies Questions & Answers

Host file and domain name

Hi all, I've got a question, it's probably a basic problem, but as i'm new to unix thought i'd try this forum out. The problem is, i'm trying to use to alias entries on the hosts file, which point to an NT IIS Server. The DNS server is a unix sun solaris. On the sun, i've filled in the... (2 Replies)
Discussion started by: nickad
2 Replies
Login or Register to Ask a Question

Featured Tech Videos