Note that there are some explanatory texts on larger screens.

plurals
  1. POVerify random URLs on a network in Java
    text
    copied!<p>This question may be a bit too low-level, but I couldn't find an answer already.</p> <p>I'm typing this next paragraph so that you can correct me/ explain the things I refer to unwittingly. You know in a web browser you can type directory paths from your own computer, and it will bring them up? Apparently, it also works with pages within a local network. If there's another page on the same subnet, you can access it with "http://pagename/".</p> <p>On the network I'm a part of, there are a lot of these pages, and they all (or mostly) have common, single-word names, such as "http://word/" . I want to test, using Java, a dictionary of common words to see which exist as locations on the network. Of course, there's probably an easier way if I know the range of ip addresses on the network, which I do. However, I get the "page not found" page if I try typing the IP address of, say, "http://word/" (which I get from ping), into the address bar. This is true even if "http://word/" works.</p> <p>So say I loop through my word bank. How can I test if a URL is real? I've worked out how to load my word bank. Here's what I have right now </p> <pre><code> URL article=new URL("http://word"); //sample URL URLConnection myConn=article.openConnection(); Scanner myScan=new Scanner(new InputStreamReader(myConn.getInputStream())); System.out.println(myScan.hasNext()); //Diagnostic output </code></pre> <p>This works when the URL is constructed with a valid URL. When it gets passed a bad URL, the program just ignores the <code>System.out.println</code>, not even making a new line. I know that different browsers show different "page not found" screens, and that these have their own html source code. Maybe that's related to my problem?</p> <p>How can I test if a URL is real using this method? Is there a way to test it with IP addresses, given my problem? or, why am I having a problem typing in the IP address and not the URL?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload