7
\$\begingroup\$

Introduction

Wardialing was a very interesting way to try to hack people back in the '80s and '90s. When everyone used dial-up, people would dial huge amounts of numbers to search for BBS's, computers, or fax machines. If it was answered by a human or answering machine, it hung up and forgot the number. If it was answered by a modem or a fax machine, it would make note of the number.

"Of course, you realize this means War...dialing?" <--- Pun made by @Shaggy

Challenge

Your job is to make a URL wardialer. Something that tests and checks if it's a valid website from one letter of the alphabet.

Constraints

  • Program must take user input. This input has to be a letter of the alphabet, no numbers. Just one letter of the alphabet and form multiple URLs that start with the letter. Input letter will be lowercase, not uppercase.
  • Standard loopholes apply.
  • You must make 8 URLs from 1 letter, and test to see if it is a valid site.
  • If you hit an error (not a response code), instead of leaving it blank, go ahead and return a 404
  • If you hit a redirect (3xx), return a 200 instead.
  • You may output the results in any reasonable format, as long as it includes the website name, status codes for all the websites and the redirects.
  • This is , so shortest amount of bytes wins.

What counts as a URL for this challenge?

http://{domain-name}.{com or net or org}

For this challenge, the domain name should only be 4 letters long, no more, no less.

What should I test?

For each 4 letter domain name, test it against three top-level domains (.com, .net, .org). Record all the response codes from each URL, remember from the constraints that any (3xx) should return 200 and be recorded as a redirect in the output and any error getting to the website should result in a 404.

Input

a

Output

+---------+------+------+------+------------+
| Website | .com | .net | .org | Redirects? |
+---------+------+------+------+------------+
| ajoe    | 200  | 200  | 200  | .com, .net |
+---------+------+------+------+------------+
| aqiz    | 200  | 404  | 404  | no         |
+---------+------+------+------+------------+
| amnx    | 200  | 503  | 404  | .com       |
+---------+------+------+------+------------+
| abcd    | 200  | 404  | 200  | .com       |
+---------+------+------+------+------------+
| ajmx    | 200  | 503  | 404  | no         |
+---------+------+------+------+------------+
| aole    | 200  | 200  | 200  | .com       |
+---------+------+------+------+------------+
| apop    | 404  | 200  | 200  | .net       |
+---------+------+------+------+------------+
| akkk    | 200  | 200  | 200  | .com       |
+---------+------+------+------+------------+
\$\endgroup\$
  • 1
    \$\begingroup\$ As a more modern human, what exactly was the point of wardialing? What did you use the numbers for? \$\endgroup\$ – Beta Decay May 23 '17 at 15:42
  • 1
    \$\begingroup\$ @BetaDecay Typically, they were used to find computers, BBS's, or pretty much anything that could be connected to a computer modem. Once a number was found that could, the user could try to guess the user account to gain access to the system over dialup. \$\endgroup\$ – KuanHulio May 23 '17 at 15:46
  • \$\begingroup\$ Are you sure it's only in the 80s or 90s? 'Cause I often get calls that hang up after one second... \$\endgroup\$ – feersum May 23 '17 at 16:01
  • 4
    \$\begingroup\$ If you've seen the movie WarGames, I believe the protagonist does some of this. \$\endgroup\$ – Stephen May 23 '17 at 16:02
  • 1
    \$\begingroup\$ That's where the name wardialing came from, I assume @StephenS and well, it never really stopped but was more prominent in the 80s and 90s. Not a lot of people use dialup any more. \$\endgroup\$ – KuanHulio May 23 '17 at 16:04
0
+50
\$\begingroup\$

Bash, 90 bytes

for i in $1{100..104}.{com,net,org};{ echo $i;(curl -IL $i 2>:||echo HTTP 404)| grep HTTP;}

Sample output:

b100.com
HTTP/1.1 301 Moved Permanently
HTTP/1.1 200 OK
b100.net
HTTP/1.1 301 Moved Permanently
HTTP/1.1 200 OK
b100.org
HTTP 404
b101.com
HTTP/1.1 301 Moved Permanently
HTTP/1.1 200 OK
b101.net
HTTP/1.1 406 Not Acceptable
b101.org
HTTP/1.1 406 Not Acceptable
b102.com
HTTP/1.1 200 OK
b102.net
HTTP 404
b102.org
HTTP 404
b103.com
HTTP/1.1 301 Moved Permanently
HTTP/1.1 200 OK
b103.net
HTTP 404
b103.org
HTTP 404
b104.com
HTTP/1.1 301 Moved Permanently
HTTP/1.1 200 OK
b104.net
HTTP/1.1 301 Moved Permanently
HTTP/1.1 200 OK
b104.org
HTTP 404
\$\endgroup\$
  • \$\begingroup\$ working on changes, need to transform 3XX in 200 and avoid user agent problems \$\endgroup\$ – marcosm Jun 1 '17 at 14:10
2
\$\begingroup\$

Python 2 + requests, 198 191 bytes

from requests import*
def f(c):
 for i in range(24):
	u='http://'+c+`i/3`*3+'.'+'cnooermtg'[i%3::3]
	try:a=get(u,allow_redirects=0).status_code
	except:a=404
	if a/100==3:a='200 R'
	print u,a

Sample output for a:

http://a000.com 404
http://a000.net 404
http://a000.org 404
http://a111.com 200
...
http://a666.org 502
http://a777.com 403
http://a777.net 200 R
http://a777.org 200
\$\endgroup\$
  • \$\begingroup\$ I think the question was to produce all four-glyph names, not just the 1000 or so that start with a and end in a digit. The example output contains a test against ajoe.com which your code cannot check. \$\endgroup\$ – Draco18s May 23 '17 at 20:51
  • \$\begingroup\$ @Draco18s You must make 8 URLs from 1 letter, and test to see if it is a valid site. does not sound like we should generate all url's. \$\endgroup\$ – ovs May 23 '17 at 20:58
  • \$\begingroup\$ Ah, yes, I missed that. Carry on. \$\endgroup\$ – Draco18s May 23 '17 at 21:10
1
\$\begingroup\$

Ruby, 145 + 10 = 155 bytes

+ 10 bytes for command line arguments.

Probably not winning any beauty contests with this:

x=[*$<.getc+?a*3..?z*4]
24.times{|i|r=Net::HTTP.get_response(URI(p"http://#{x[i/3]}."+'comnetorg'[i*3%9,3])).code rescue"404"
p r=~/^3/?"200R":r}

Run with ruby -rnet/http wardialing.rb

Example:

$ ruby -rnet/http wardialing.rb <<< g
"http://gaaa.com"
"200R"
"http://gaaa.net"
"200"
"http://gaaa.org"
"200"
"http://gaab.com"
"200"
"http://gaab.net"
"200"
"http://gaab.org"
"200"
"http://gaac.com"
"404"

(etc)
\$\endgroup\$
0
\$\begingroup\$

PHP, 221 bytes

for($c=8;$c--;){$u=$argv[1];for($i=3;$i--;)$u.=chr(rand(97,122));for($z=0;$z<3;){$r="$u.".['com','net','org'][$z++];$h=get_headers("http://$r");$s=$h?substr($h[0],9,3):404;$t=(3==intval($s/100))?"200R":$s;echo"$r $t\n";}}

With CRs and indentation

for($c=8;$c--;){
    $u=$argv[1];
    for($i=3;$i--;)$u.=chr(rand(97,122));
    for($z=0;$z<3;){
        $r="$u.".['com','net','org'][$z++];
        $h=get_headers("http://$r");
        $s=$h?substr($h[0],9,3):404;
        $t=(3==intval($s/100))?"200R":$s;
        echo"$r $t\n";
    }
}

Sample output on 'b':

bnjz.com 404
bnjz.net 200
bnjz.org 404
bkxw.com 200
bkxw.net 200
bkxw.org 403
biak.com 200
biak.net 403
biak.org 200R
bpzb.com 200
bpzb.net 200
bpzb.org 404
bigr.com 404
bigr.net 200
bigr.org 200
bcei.com 404
bcei.net 200R
bcei.org 200
bexc.com 200
bexc.net 200
bexc.org 404
bset.com 404
bset.net 200
bset.org 200
\$\endgroup\$
0
\$\begingroup\$

NodeJS, 249 246 bytes

-3 bytes thanks to @ASCII-only.

c=>{r=_=>Math.random().toString(36).slice(-3),o="",q=i=>(u=`http://${n=i%3?n:c+r()}.`+["com","net","org"][i%3],o+=u+" ",d=r=>(o+=(/^3/.test(s=r.statusCode||404)?"200R":s)+`
`,--i?q(i):console.log(o)),require("http").get(u,d).on("error",d)),q(24)}

Creates random three-letter strings from 1-9 and a-z for each domain. Redirects are shown as 200R.

Try it online
(Note: may take a minute or two to complete all requests)

Sample output

http://a9k9.com 200
http://a9k9.net 404
http://a9k9.org 404
http://a529.com 200
http://a529.net 404
http://a529.org 404
http://asor.com 200R
http://asor.net 404
http://asor.org 404

Longer version with table output, 278 bytes

c=>{r=_=>Math.random().toString(36).slice(-3),o=h=`name .com    .net    .org
`,q=i=>(i%3||(n=c+r(),o+=n+`    `),u=`http://${n}.`+h.substr(6+i%3*5,3),d=r=>(o+=(/^3/.test(s=r.statusCode||404)?"200R":s)+(++i%3?` `:`
`),i<24?q(i):console.log(o)),require("http").get(u,d).on("error",d)),q(0)}

Whitespace in name .com .net .org and n+` ` are literal tab characters.

Sample table output

name    .com    .net    .org
aa4i    200     200     200
a66r    404     404     404
anmi    200     200     403
aaor    403     200R    200R
\$\endgroup\$
  • \$\begingroup\$ I followed the link to 'Try it online' but only got "undefined" as output. \$\endgroup\$ – Octopus May 31 '17 at 22:44
  • 1
    \$\begingroup\$ @Octopus It takes a minute or two to complete all of the requests, and for some reason the online interpreter outputs "undefined" right at the start. Running locally from command line does not output that, though. I'll add that as a note to the post. \$\endgroup\$ – Justin Mariner May 31 '17 at 22:55
  • \$\begingroup\$ 246: c=>{r=_=>Math.random().toString(36).slice(-3),o="",q=i=>(u=`http://${n=i%3?n:c+r()}.`+['com','org','net'][i%3],o+=u+" ",d=r=>(o+=(/^3/.test(s=r.statusCode||404)?"200R":s)+` `,--i?q(i):console.log(o)),require("http").get(u,d).on("error",d)),q(24)} \$\endgroup\$ – ASCII-only Jun 2 '17 at 2:24
  • \$\begingroup\$ @ASCII-only thanks, updated. \$\endgroup\$ – Justin Mariner Jun 2 '17 at 18:02
0
\$\begingroup\$

q/kdb+, 392 378 300 276 bytes

Solution:

t:{
  w:y,($:)x;
  r:@[{"J"$-3#12#(`$":http://",x)y}[w;];"GET / HTTP/1.1\r\nHost:",w,4#"\r\n";404];
  (x,`w`r)!(r;`$y;$[(r>299)&r<400;[r:200;x];`])
  }
f:{
  R:(`w,x,`r)xcols(,/)each(x)t\:/:{x,/:3 cut 24?.Q.a}y;
  (`Website,x,`$"Redirects?")xcol update r:`No from R where r=`
  }[`.com`.org`.net;]

Example:

q)f"a"
Website .com .org .net Redirects?
---------------------------------
amik    200  200  200  .net      
abjl    200  200  503  No        
afuw    403  200  200  No        
agby    200  200  200  No        
afen    200  200  200  .net      
ajch    200  404  200  No        
aaro    200  200  200  No        
ajsr    200  404  503  No   

Notes:

Current solution is fairly hefty... Half the code is trying to fetch a URL, the other half is presenting the results nicely, unsure how much further I can golf this.

Explanation:

Function t

w:y,($:)x       // convert suffix (`.com) to string, prepend host and save in w
@[x;y;404]      // try function x with parameter y, on error return 404
"GET /..."      // HTTP GET request in shortest form
`:http://x y    // open web connection to x, send request y
-3#12#          // truncate output to 12 chars, take last 3 chars
"J"$            // cast result to long
$[x;y;z]        // if x then y, else z
(x)!(y)         // create a dictionary with x as keys, y as values

Function f

24?.Q.a         // take 24 random characters from a-z
x,/:3 cut       // cut into 3-character lists, prepend input 'x'
t\:/:           // call function t with each combination of left and right
(,/) each       // raze (reduce) each result
xcols           // re-order columns into output format
xcol            // rename columns
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.