Forums
New posts
New posts
Search forums
Market
Domains/Websites Wanted
.com Domain Market
gTLD Domain Market
ccTLD Domain Market
Web3 Domain Market
Third-Level Domain Market
Adult Domain Market
What's New
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Account Upgrade
Premium Members Directory
Log in
Register
What's New
calendar
Search
Search
Search titles only
By:
New posts
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
Forums
Domain Discussion
Domain Beginners and Newbies
Best Domain Availability Checking Apis?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="katherine" data-source="post: 2217307" data-attributes="member: 63835"><p>Here is a reviewed version of the script.</p><p></p><p>Say you have a list of domains to check in a file <strong>domains.txt</strong> like this:</p><p>[CODE]</p><p>thisdomainsdoesnot-exist.com</p><p>.com</p><p>test.com</p><p>cctld.ru</p><p>[/CODE]</p><p>NB: domains can be in any TLD.</p><p></p><p>This code will process the input file and create a results file <strong>domains.txt.results.csv</strong> in the same directory.</p><p></p><p>[CODE]#!/bin/bash</p><p></p><p>export LC_ALL=C</p><p>echo -n "List to check: "</p><p>read inputfile</p><p>echo "List: $inputfile"</p><p></p><p>if [ ! -f "$inputfile" ]; then</p><p> echo "File $inputfile does not exist, exit"</p><p> exit 0</p><p>else</p><p> filename=$(basename "$inputfile")</p><p> outputfile=$(dirname "$inputfile")/"$filename.results.csv"</p><p> echo "Output file: $outputfile"</p><p>fi</p><p></p><p>echo "domain,error,status,NS" > "$outputfile"</p><p>while read domain</p><p>do</p><p> echo "Processing domain: $domain"</p><p> ns=$(dig -t ns +short "$domain" 2> /dev/null)</p><p> err=$?</p><p> if [ "$err" -ne 0 ]; then</p><p> echo "An error occured (code: $err)"</p><p> echo "$domain,$err,ERR" >> "$outputfile"</p><p> else</p><p> # response empty ?</p><p> if [ ! -z "$ns" ]; then</p><p> echo -n "NS found: "</p><p> nslist=$(echo "$ns" | tr "\n" " ")</p><p> echo "$nslist"</p><p> echo "$domain,$err,NS,$nslist" >> "$outputfile"</p><p> else</p><p> echo "No NS found"</p><p> echo "$domain,$err,NXD" >> "$outputfile"</p><p> fi</p><p> fi</p><p></p><p>done < $inputfile</p><p>[/CODE]</p><p>Result:</p><p>[CODE]</p><p>domain,error,status,NS</p><p>thisdomainsdoesnot-exist.com,0,NXD</p><p>.com,10,ERR</p><p>test.com,0,NS,ns66.worldnic.com. ns65.worldnic.com.</p><p>cctld.ru,0,NS,ns.cctld.ru. ns1.cctld.ru.</p><p>[/CODE]</p><p></p><p>Now you have a neat file in CSV format.</p><ul> <li data-xf-list-type="ul">First column: the domain name</li> <li data-xf-list-type="ul">Second column: error code returned by dig (0 = OK)</li> <li data-xf-list-type="ul">Third column: status:<ol> <li data-xf-list-type="ol">ERR: error occured</li> <li data-xf-list-type="ol">NXD: NXDOMAIN</li> <li data-xf-list-type="ol">NS: name servers found, domain exists</li> </ol></li> <li data-xf-list-type="ul">Fourth column: the list of name servers if any</li> </ul><p>To make the process more efficient, multiple DNS checks should be done in parallel by spawning the process into multiple threads (using xargs for example).</p><p>Your homework <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /></p></blockquote><p></p>
[QUOTE="katherine, post: 2217307, member: 63835"] Here is a reviewed version of the script. Say you have a list of domains to check in a file [B]domains.txt[/B] like this: [CODE] thisdomainsdoesnot-exist.com .com test.com cctld.ru [/CODE] NB: domains can be in any TLD. This code will process the input file and create a results file [B]domains.txt.results.csv[/B] in the same directory. [CODE]#!/bin/bash export LC_ALL=C echo -n "List to check: " read inputfile echo "List: $inputfile" if [ ! -f "$inputfile" ]; then echo "File $inputfile does not exist, exit" exit 0 else filename=$(basename "$inputfile") outputfile=$(dirname "$inputfile")/"$filename.results.csv" echo "Output file: $outputfile" fi echo "domain,error,status,NS" > "$outputfile" while read domain do echo "Processing domain: $domain" ns=$(dig -t ns +short "$domain" 2> /dev/null) err=$? if [ "$err" -ne 0 ]; then echo "An error occured (code: $err)" echo "$domain,$err,ERR" >> "$outputfile" else # response empty ? if [ ! -z "$ns" ]; then echo -n "NS found: " nslist=$(echo "$ns" | tr "\n" " ") echo "$nslist" echo "$domain,$err,NS,$nslist" >> "$outputfile" else echo "No NS found" echo "$domain,$err,NXD" >> "$outputfile" fi fi done < $inputfile [/CODE] Result: [CODE] domain,error,status,NS thisdomainsdoesnot-exist.com,0,NXD .com,10,ERR test.com,0,NS,ns66.worldnic.com. ns65.worldnic.com. cctld.ru,0,NS,ns.cctld.ru. ns1.cctld.ru. [/CODE] Now you have a neat file in CSV format. [LIST] [*]First column: the domain name [*]Second column: error code returned by dig (0 = OK) [*]Third column: status: [LIST=1] [*]ERR: error occured [*]NXD: NXDOMAIN [*]NS: name servers found, domain exists [/LIST] [*]Fourth column: the list of name servers if any [/LIST] To make the process more efficient, multiple DNS checks should be done in parallel by spawning the process into multiple threads (using xargs for example). Your homework :) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Domain Discussion
Domain Beginners and Newbies
Best Domain Availability Checking Apis?
Top
Bottom