13
\$\begingroup\$

Challenge

The challenge is simple, using http://isup.me, determine whether an inputted website is up or down.

If the site is up, you should return a truthy value and if the site is down, you should return a falsey value.

Rules

The input will be a web address such as stackexchange.com or google.co.uk. The input will never have http://, https:// etc. at the start of the string, but may have www. or codegolf. at start etc.

You should use the site isup.me/URL where URL is the input.

When a site is up, it will look like:

http://isup.me/codegolf.stackexchange.com

If a site is down, it will look like:

http://isup.me/does.not.exist

URL shorteners are disallowed apart from isup.me.

Example inputs

Probably up (depending on current circumstances):

google.de
codegolf.stackexchange.com
worldbuilding.meta.stackexchange.com
tio.run
store.nascar.com
isup.me

Will be down:

made.up.com
fake.com.us
why.why.why.delilah
store.antarcticrhubarbassociation.an

Winning

Shortest code in bytes wins.

\$\endgroup\$
  • 21
    \$\begingroup\$ By the way: "made.up.co.uk" is actually up. \$\endgroup\$ – GiantTree Jul 2 '17 at 23:40
  • 8
    \$\begingroup\$ I've just registered fake.com.us to mess with your test cases! \$\endgroup\$ – YSC Jul 3 '17 at 9:18
  • 14
    \$\begingroup\$ But what if isup.me is down? \$\endgroup\$ – Okx Jul 3 '17 at 12:01
  • 2
    \$\begingroup\$ @Oks Are you sure it's not just you? \$\endgroup\$ – Pierre Arlaud Jul 3 '17 at 13:05
  • 3
    \$\begingroup\$ Recommended test case: isup.me. It returns a result other than what, say, google.com may return. \$\endgroup\$ – Okx Jul 3 '17 at 14:02

16 Answers 16

16
\$\begingroup\$

sh (+ curl + grep), 28 26 bytes

curl -L isup.me/$1|grep ^I

Outputs via exit status (0 for up, 1 for down). Looks for an I at the beginning of a line, which matches when the domain is up (even for the special case of isup.me/isup.me).

\$\endgroup\$
  • 1
    \$\begingroup\$ curl -L isup.me/$1|grep u! saves 1 byte. This assumes that ! is not a valid character in the domain name. \$\endgroup\$ – user4768 Jul 3 '17 at 7:11
  • \$\begingroup\$ Is 0 truthy in sh? \$\endgroup\$ – Shaggy Jul 3 '17 at 8:20
  • 1
    \$\begingroup\$ 0 is indeed truthy in sh, with all nonzero values being falsy. Also, IMO it's really nice that the sh version is so short, since it's absolutely the right language for this task even without considering golfing. \$\endgroup\$ – Score_Under Jul 3 '17 at 8:46
  • \$\begingroup\$ That said this will fail on something like spthissitedoesntexist.invalid \$\endgroup\$ – Score_Under Jul 3 '17 at 8:53
  • 1
    \$\begingroup\$ It matches on my machine. It matches this bit: <a href="http://spthissitedoesntexist.invalid" class="domain">spthissitedoesntexist.invalid</a> Specifically it matches inside the href. \$\endgroup\$ – Score_Under Jul 3 '17 at 9:39
5
\$\begingroup\$

Stacked, 44 bytes

['http://isup.me/'\+[CS'!'eq sum 2=out]curl]

Asynchronous function that outputs 0 if the site is not up, and any other number greater than 0 if it is up.

Example a:

['http://isup.me/'\+['s u'split#'1-put]curl] @:isup

'Is google up?' put 'google.com' isup

Output (probably): Is google up? 1

\$\endgroup\$
  • \$\begingroup\$ Can you add linked to Stacked GH page? \$\endgroup\$ – Downgoat Jul 2 '17 at 23:17
  • \$\begingroup\$ @Downgoat Done. \$\endgroup\$ – Conor O'Brien Jul 2 '17 at 23:17
  • \$\begingroup\$ If this is checking for an occurrence of s u, note that this occurs on any input beginning with u (whether up or down). \$\endgroup\$ – Anders Kaseorg Jul 3 '17 at 1:16
  • \$\begingroup\$ @AndersKaseorg Fixed, thanks. \$\endgroup\$ – Conor O'Brien Jul 3 '17 at 1:45
  • \$\begingroup\$ Better example: 'Is example.com up?' put 'example.com' isup output (not just probably but surely): Is example.com up? 1 \$\endgroup\$ – Erik the Outgolfer Jul 3 '17 at 9:18
4
\$\begingroup\$

Kotlin REPL - 131 108 106 93 79 55 53 64 63 bytes

First try at Kotlin golfing.
Expects the website in a variable or value named a.

Now with reduced whitespace.
Who said "loo" isn't enough?
Fixed and shorter, doesn't rely on http://isup.me anymore.
No need to open the connection ourselves, just get the stream of data (or not)
The task was to use http://isup.me, right? Also: < is not a valid character in a URL.
Now works with isup.me as the website

Now reads the website as a line, because one can't assume a variable to contain the website.

"m h" !in java.net.URL("http://isup.me/"+readLine()).readText()

Reads one line containing just the website.
Checks for the m h part of from here that is sent when a site is down.

Returns "true" or "false" respectively.


As a Lambda - 172 120 118 99 85 67 66 bytes

{a:String->"m h" !in java.net.URL("http://isup.me/$a").readText()}

Can be invoked directly:

{ ... }("google.com")
\$\endgroup\$
  • \$\begingroup\$ forgive me if I'm wrong, but couldn't this be converted to a lambda fairly easily? \$\endgroup\$ – Nick Clifford Jul 2 '17 at 23:17
  • \$\begingroup\$ @NickClifford sure, but it would actually be longer due to the argument and type definition (15 chars because type inference doesn't work here) \$\endgroup\$ – GiantTree Jul 2 '17 at 23:19
  • 3
    \$\begingroup\$ I don't know the language, but it seems like you are checking to see if "loo" is in the returned text. Is it not the case that this text also returns the (variable) site name? And if it is, does that mean you get false negatives for sites like loo.com? \$\endgroup\$ – cole Jul 3 '17 at 0:01
  • \$\begingroup\$ @Cole you are definitely right, I completely forgot about this (I was only testing Google and the fake website). I will update the code next morning (it's 2am where I am currently) \$\endgroup\$ – GiantTree Jul 3 '17 at 0:06
  • \$\begingroup\$ This one will fail on sites with loo in the name. electric.boogaloo doesn't exist but the string loo will be in the output there. \$\endgroup\$ – Score_Under Jul 3 '17 at 9:02
2
\$\begingroup\$

Python 2 or 3 with Requests (70 69 68 bytes)

from requests import*;lambda u:"u. "in get("http://isup.me/"+u).text

1 byte shaved: "u. "" u" Nope, not a valid optimisation.
1 byte shaved: __import__('requests').from requests import*;

This is now really a REPL-only piece of code, and after running this line the function will be named _.

\$\endgroup\$
  • 1
    \$\begingroup\$ Syntax error at the end (probably a stray )). \$\endgroup\$ – Erik the Outgolfer Jul 3 '17 at 10:47
  • 1
    \$\begingroup\$ Fails for inputs starting with u. \$\endgroup\$ – Erik the Outgolfer Jul 3 '17 at 10:49
  • 1
    \$\begingroup\$ Using from requests import* and get is 1 byte shorter. \$\endgroup\$ – mbomb007 Jul 3 '17 at 16:59
  • 1
    \$\begingroup\$ it is not REPL-only, it's allowed to answer with unnamed functions (lambdas in python) \$\endgroup\$ – Felipe Nardi Batista Jul 4 '17 at 13:31
  • \$\begingroup\$ It is an unnamed function, but the script as a whole can't be used as an expression (since it uses import), so I think it's safer to just call it a REPL line. \$\endgroup\$ – Score_Under Jul 4 '17 at 15:41
2
\$\begingroup\$

Python3 141 133 113 192 141 bytes

Requires Selenium (including webdriver) for python.

Thanks to @cairdcoinheringaahing for reducing 42 bytes!
Thanks to @V.Courtois for pointing out a simple fix!

from selenium import*
d=webdriver.Firefox();d.get("http://isup.me/"+input());print("up"in d.find_element_by_xpath("//*[@id='content']/p[1]"))

Prints 1 if site is up and running, else prints 0.

Ungolfed version:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
urlToTest = "www.f.com"
driver = webdriver.Firefox()
driver.get("http://downforeveryoneorjustme.com/"+urlToTest)
res = driver.find_element_by_xpath("//*[@id='content']/p[1]")
print(1 if "up" in res.text else 0)
\$\endgroup\$
  • \$\begingroup\$ They said isup.me is fine in the comments; you can win some bytes :) \$\endgroup\$ – V. Courtois Jul 3 '17 at 7:12
  • 1
    \$\begingroup\$ -1 This is a snippet. Full programs or functions are required and input cannot be assumed in a variable (such as t). Also, you can golf the print statement to print("up"in r.text) \$\endgroup\$ – caird coinheringaahing Jul 3 '17 at 16:45
  • \$\begingroup\$ @cairdcoinheringaahing Okay, will make those changes, thank you! This is my second answer, so I didn't know whether to post a snippet or a full fledged program. So I posted both. \$\endgroup\$ – Rahul Bharadwaj Jul 4 '17 at 5:46
  • \$\begingroup\$ 141 bytes \$\endgroup\$ – caird coinheringaahing Jul 4 '17 at 6:15
2
\$\begingroup\$

Javascript (ES6), 74 66 bytes

f=s=>fetch('//isup.me/'+s).then(r=>r.text()).then(t=>/u!/.test(t))

Thanks to @Shaggy, who brought to my attention that a resolved promise counts as output.

Problem with this solution that it will throw a CORS error unless I test it on a page that's already at isup.me. But currently, that gets redirected to downforeveryoneorjustme.com

Older version:

f=s=>fetch('//isup.me/'+s).then(r=>r.text()).then(t=>alert(t.match(/u!/)))

\$\endgroup\$
  • 1
    \$\begingroup\$ You can get rid of the alert and just return the Promise. See here. I think you might also be able to make a saving with /u!/.test(t). \$\endgroup\$ – Shaggy Jul 4 '17 at 8:25
1
\$\begingroup\$

Pyth, 24 bytes

}" u"s'+"http://isup.me/

Return True if the site is up, False otherwise. The input URL must be quoted. That cannot be tested on the online interpreter because ' is disabled on it for safety reasons; instead you will need a local copy of Pyth.

Explanation

                        Q    # Implicit input
       +"http://isup.me/     # Concatenate "http://isup.me/" with the input
      '                      # Open the URL
     s                       # Concatenate all the lines of the returned HTML page
}" u"                        # Test whether " u" is in the page or not
\$\endgroup\$
  • 1
    \$\begingroup\$ Fails for inputs starting with u. \$\endgroup\$ – Erik the Outgolfer Jul 3 '17 at 10:57
1
\$\begingroup\$

05AB1E, 22 bytes

"isup.me/ÿ".w#214è'‚‰Q

Try it online!

Unfortunately "isup.me/ÿ".w§„ uå doesn't seem to work.

\$\endgroup\$
1
\$\begingroup\$

PowerShell, 32 bytes

(iwr isup.me/$args)-notmatch'u!'
\$\endgroup\$
  • \$\begingroup\$ Missed your answer before I posted mine sorry! some weird irm behavior saved me a bunch on this one. mine here \$\endgroup\$ – colsw Jul 4 '17 at 9:50
1
\$\begingroup\$

PowerShell, 25 Bytes

!(irm isup.me/$args).html

Uses the fact that Invoke-RestMethod returns the page with a .html property only on failure. (no idea why exactly this happens...)

inverts the line to convert to bool, outputs True for a live site or False for a down site.

PS C:\Users\sweeneyc\Desktop> .\Test-SiteUp.ps1 "connorlsw.com"
True
PS C:\Users\sweeneyc\Desktop> .\Test-SiteUp.ps1 "connorlsw.notawebsite"
False
PS C:\Users\sweeneyc\Desktop> .\Test-SiteUp.ps1 "google.com"
True
PS C:\Users\sweeneyc\Desktop> .\Test-SiteUp.ps1 "isthisreallyasite.com"
False
\$\endgroup\$
  • \$\begingroup\$ @TessellatingHeckler irm returns plaintext for non-parsable pages, I was going to do a plaintext match so it would have behaved the same as iwr, regardless I guess if it works it works. \$\endgroup\$ – colsw Jul 6 '17 at 8:48
1
\$\begingroup\$

Halovi, 20 bytes

oisup.me/⁰
\p
ye$hd0

Outputs p. if the site is down, and e. if it is up.

Explanation:

oisup.me/⁰  ~# Open the concatination of "isup.me/" and arg0
\p          ~# Select first p element
ye$hd0      ~# Edit text with neovim and output result:
            ~#   Go one character before the end of the line and ..
            ~#   delete until beginning
\$\endgroup\$
1
\$\begingroup\$

Haskell (Lambdabot), 157 bytes

import Data.ByteString.Lazy.Char8
import Network.HTTP.Simple
f s=httpLBS(parseRequest_$"http://isup.me/"++s)>>=print.not.isInfixOf"u!".unpack.getResponseBody

Unfortunately you can't import Network.HTTP.Simple on tio.run, the easiest way to test would be to run this script (you'll need stack):

#!/usr/bin/env stack
-- stack --install-ghc --resolver lts-8.19 runghc --package http-conduit

import Data.ByteString.Lazy.Char8
import Network.HTTP.Simple
import Data.List

main :: IO ()
main = mapM_ test [ "google.de", "made.up.com"]
  where test url = print ("testing "++url) >> f url

f :: String -> IO ()
f s=httpLBS(parseRequest_$"http://isup.me/"++s)
 >>=print.not.isInfixOf"u!".unpack.getResponseBody
\$\endgroup\$
0
\$\begingroup\$

Go, 111 bytes

In typical Go fashion, the shortest method is to shell it out.

import"os/exec"
func h(a string)bool{return exec.Command("sh","-c","curl -L isup.me/"+a+"|grep ^I").Run()!=nil}

Other implementations here: https://play.golang.org/p/8T5HSDQFmC

\$\endgroup\$
0
\$\begingroup\$

Clojure, 63 bytes

#(clojure.string/includes?(slurp(str"http://isup.me/"%))"'s j")

Checks if the HTML returned by slurp contains the string "'s j" (as in, "It 's just you"). I might be able to find a smaller string that's unique to the page, but it would at most save me 2 bytes. It would also potentially make it less accurate. "'s j" isn't going to appear in the markup anywhere except in that one scenario. A string like "u." however could potentially appear in the URL, which would break it.

(defn is-up? [site]
  (clojure.string/includes?
    (slurp (str "http://isup.me/" site))
    "'s j"))
\$\endgroup\$
0
\$\begingroup\$

Nim, 108 bytes

import httpclient,strutils
echo newhttpclient().getcontent("//isup.me/"&stdin.readline.string).find("ks ")<0

Unfortunate that strutils is needed for contains.

Learning Nim, tips appreciated!

\$\endgroup\$
0
\$\begingroup\$

PHP, 82 78 bytes

<?=$i=$argv[1],+!preg_match("/!.*$i/",file_get_contents("http://isup.me/$i"));

Example i/o runs:

$ php script.php google.com
> google.com1

Example 2

$ php script.php does.not.exist
> does.not.exist0
\$\endgroup\$
  • \$\begingroup\$ Almost the shortest solution possible. Empty output is "a falsy value" too, so you can remove the +. And with $argn instead of $argv[1] you could use another 6 (minus 1) bytes. \$\endgroup\$ – Titus Dec 17 '17 at 18:33

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.