Is this site down or is it just me?

13

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.

Beta Decay

Posted 2017-07-02T22:43:13.990

Reputation: 21 478

If URL shorteners aren't allowed, should we use downforeveryoneorjustme.com or isup.me ? – Conor O'Brien – 2017-07-02T22:49:23.937

@ConorO'Brien No, I'll make an exception for isup.me – Beta Decay – 2017-07-02T22:50:22.077

21By the way: "made.up.co.uk" is actually up. – GiantTree – 2017-07-02T23:40:46.637

@GiantTree Hmm... technically up but doesn't exist. – Erik the Outgolfer – 2017-07-03T08:50:25.470

1@EriktheOutgolfer Irrelevant – Pierre Arlaud – 2017-07-03T08:56:59.517

8I've just registered fake.com.us to mess with your test cases! – YSC – 2017-07-03T09:18:18.653

@PierreArlaud I mean, it's just a registrar page. – Erik the Outgolfer – 2017-07-03T10:33:49.623

@Erik isup.me still registers it as up though – Beta Decay – 2017-07-03T10:35:53.717

14But what if isup.me is down? – Okx – 2017-07-03T12:01:08.930

2@Oks Are you sure it's not just you? – Pierre Arlaud – 2017-07-03T13:05:09.547

3Recommended test case: isup.me. It returns a result other than what, say, google.com may return. – Okx – 2017-07-03T14:02:50.700

@Okx Thanks, that's a good one – Beta Decay – 2017-07-03T14:40:11.127

I have just notified Tom Jones. He's shouting at his agent right now. – Wossname – 2017-07-03T16:59:33.987

mabye add a test case for something like qweasdzxc with no .tld - returns different results. I'd say answers should only need to take valid web addresses into account though.. – colsw – 2017-07-05T08:44:27.070

Answers

16

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).

Anders Kaseorg

Posted 2017-07-02T22:43:13.990

Reputation: 29 242

1curl -L isup.me/$1|grep u! saves 1 byte. This assumes that ! is not a valid character in the domain name. – None – 2017-07-03T07:11:31.913

Is 0 truthy in sh? – Shaggy – 2017-07-03T08:20:50.253

10 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. – Score_Under – 2017-07-03T08:46:46.337

That said this will fail on something like spthissitedoesntexist.invalid – Score_Under – 2017-07-03T08:53:35.807

@Score_Under it does work for that domain. the /sp doesn't match the sp in the domain. – None – 2017-07-03T08:59:42.757

1It matches on my machine. It matches this bit: <a href="http://spthissitedoesntexist.invalid" class="domain">spthissitedoesntexist.invalid</a> Specifically it matches inside the href. – Score_Under – 2017-07-03T09:39:31.417

@Score_Under oh, you're right. I didn't notice the / from http://. – None – 2017-07-03T10:32:29.550

@Score_Under Fixed. – Anders Kaseorg – 2017-07-03T18:13:24.407

@stanri I would not accept grep u! because the challenge specifies the result must be truthy on domains that are up. – Anders Kaseorg – 2017-07-03T18:21:58.167

5

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

Conor O'Brien

Posted 2017-07-02T22:43:13.990

Reputation: 36 228

Can you add linked to Stacked GH page? – Downgoat – 2017-07-02T23:17:22.017

@Downgoat Done. – Conor O'Brien – 2017-07-02T23:17:48.797

If this is checking for an occurrence of s u, note that this occurs on any input beginning with u (whether up or down). – Anders Kaseorg – 2017-07-03T01:16:06.803

@AndersKaseorg Fixed, thanks. – Conor O'Brien – 2017-07-03T01:45:21.480

Better example: 'Is example.com up?' put 'example.com' isup output (not just probably but surely): Is example.com up? 1 – Erik the Outgolfer – 2017-07-03T09:18:22.840

@EriktheOutgolfer How is that a better example ? – Conor O'Brien – 2017-07-03T19:45:41.467

4

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")

GiantTree

Posted 2017-07-02T22:43:13.990

Reputation: 885

forgive me if I'm wrong, but couldn't this be converted to a lambda fairly easily? – Nick Clifford – 2017-07-02T23:17:06.580

@NickClifford sure, but it would actually be longer due to the argument and type definition (15 chars because type inference doesn't work here) – GiantTree – 2017-07-02T23:19:01.973

3I 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? – cole – 2017-07-03T00:01:27.810

@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) – GiantTree – 2017-07-03T00:06:16.217

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. – Score_Under – 2017-07-03T09:02:23.420

I updated the code, shortened it a bit and use a similar method to the curl solutions. – GiantTree – 2017-07-03T11:58:52.273

maybe .openStream() instead of openConnection().connect()? – Olivier Grégoire – 2017-07-03T12:25:19.820

@OlivierGrégoire thanks, that saves a few more characters. – GiantTree – 2017-07-03T13:02:36.637

Yeah, I used the same in Java answer below. – Olivier Grégoire – 2017-07-03T13:06:36.947

Well, I re-read the challenge and the goal is to use the proxy service isup.me, not testing it yourself. So I deleted my answer and yours is invalid too :( – Olivier Grégoire – 2017-07-03T13:28:35.783

@OlivierGrégoire you are right. Back to the drawing board. – GiantTree – 2017-07-03T13:36:38.183

@OlivierGrégoire Fixed it! It's even shorter thanks to extensions in Kotlin. – GiantTree – 2017-07-03T13:45:40.163

Fix for isup.me as website – GiantTree – 2017-07-03T16:32:38.860

This is invalid, as you can't just assume the input is in a variable. – Erik the Outgolfer – 2017-07-03T16:57:20.153

@EriktheOutgolfer updated the REPL part; the Lambda is still valid as it uses its argument. – GiantTree – 2017-07-03T17:03:49.297

In kotlin, is "http://isup.me/${readLine()}" not interchangeable with "http://isup.me/"+readLine()? If so, the latter is 2 bytes shorter. – Score_Under – 2017-07-03T17:17:59.610

@Score_Under it is. Thanks, I definitely use template strings too often. – GiantTree – 2017-07-03T17:19:43.340

The challenge specifies “If the site is up, you should return a truthy value”, but you return false. – Anders Kaseorg – 2017-07-03T18:18:08.593

@AndersKaseorg, you are absolutely right. I'll fix that. – GiantTree – 2017-07-03T18:19:27.387

While the challenge does specify truthy-falsey, the meta consensus seems to be for two distinct outputs (or possibly one distinct vs. everything else), so it would be arguable to map True to down and False to up.

– zbw – 2017-07-20T16:15:45.597

2

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)

Rahul Bharadwaj

Posted 2017-07-02T22:43:13.990

Reputation: 145

They said isup.me is fine in the comments; you can win some bytes :) – V. Courtois – 2017-07-03T07:12:21.403

1-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) – caird coinheringaahing – 2017-07-03T16:45:15.137

@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. – Rahul Bharadwaj – 2017-07-04T05:46:59.157

141 bytes – caird coinheringaahing – 2017-07-04T06:15:22.500

2

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 _.

Score_Under

Posted 2017-07-02T22:43:13.990

Reputation: 271

1Syntax error at the end (probably a stray )). – Erik the Outgolfer – 2017-07-03T10:47:20.973

1Fails for inputs starting with u. – Erik the Outgolfer – 2017-07-03T10:49:09.020

1Using from requests import* and get is 1 byte shorter. – mbomb007 – 2017-07-03T16:59:45.013

1it is not REPL-only, it's allowed to answer with unnamed functions (lambdas in python) – Felipe Nardi Batista – 2017-07-04T13:31:06.117

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. – Score_Under – 2017-07-04T15:41:18.777

@Score_Under yes it is accepted – Felipe Nardi Batista – 2017-07-04T16:40:09.340

2

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!/)))

Christiaan Westerbeek

Posted 2017-07-02T22:43:13.990

Reputation: 863

1

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).

– Shaggy – 2017-07-04T08:25:39.443

1

05AB1E, 22 bytes

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

Try it online!

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

Erik the Outgolfer

Posted 2017-07-02T22:43:13.990

Reputation: 38 134

1

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

Jim

Posted 2017-07-02T22:43:13.990

Reputation: 1 442

1Fails for inputs starting with u. – Erik the Outgolfer – 2017-07-03T10:57:33.587

1

PowerShell, 32 bytes

(iwr isup.me/$args)-notmatch'u!'

TessellatingHeckler

Posted 2017-07-02T22:43:13.990

Reputation: 2 412

Missed your answer before I posted mine sorry! some weird irm behavior saved me a bunch on this one. mine here

– colsw – 2017-07-04T09:50:34.513

1

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

ბიმო

Posted 2017-07-02T22:43:13.990

Reputation: 15 345

1

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

colsw

Posted 2017-07-02T22:43:13.990

Reputation: 3 195

@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. – colsw – 2017-07-06T08:48:20.467

1

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

BlackCap

Posted 2017-07-02T22:43:13.990

Reputation: 3 576

0

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

Eric Lagergren

Posted 2017-07-02T22:43:13.990

Reputation: 473

0

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"))

Carcigenicate

Posted 2017-07-02T22:43:13.990

Reputation: 3 295

0

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

kip

Posted 2017-07-02T22:43:13.990

Reputation: 141

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. – Titus – 2017-12-17T18:33:17.633

0

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!

Quelklef

Posted 2017-07-02T22:43:13.990

Reputation: 441