forked from eunbeek/findBrokenGlass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eunbee Kim
committed
Sep 30, 2020
1 parent
01d330e
commit a94c9da
Showing
7 changed files
with
170 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/.metadata/ | ||
/bin/ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
public class UrlCheckForMac { | ||
|
||
//text for mac | ||
public static final String RED = "\033[0;31m"; | ||
public static final String GREEN = "\033[0;32m"; | ||
public static final String WHITE = "\033[0;37m"; | ||
public static final String BLUE ="\033[0;34m"; | ||
public static final String RESET = "\033[0m"; | ||
|
||
// request url and check the response | ||
public static void availableURL(String host) | ||
{ | ||
|
||
try { | ||
// request url | ||
URL url = new URL(host); | ||
URLConnection con; | ||
con = url.openConnection(); | ||
|
||
// response | ||
HttpURLConnection exitCode = (HttpURLConnection) con; | ||
exitCode.setInstanceFollowRedirects(true); | ||
HttpURLConnection.setFollowRedirects(true); | ||
exitCode.setConnectTimeout(1000); | ||
|
||
|
||
// // for Mac | ||
if(exitCode.getResponseCode() >= 200 && exitCode.getResponseCode() < 300) | ||
{ | ||
|
||
System.out.println(GREEN+"["+exitCode.getResponseCode()+"] "+ host +" - Good"+RESET); | ||
|
||
} | ||
else if(exitCode.getResponseCode() >= 400 && exitCode.getResponseCode() < 500) | ||
{ | ||
System.out.println(RED+"["+exitCode.getResponseCode()+"] "+ host +" - Bad"+RESET); | ||
} | ||
else if(exitCode.getResponseCode() == 301 || exitCode.getResponseCode() == 307 || exitCode.getResponseCode() == 308 ) | ||
{ | ||
System.out.println(BLUE + "["+exitCode.getResponseCode()+"] "+ host +" - Redirect"+ RESET); | ||
|
||
// redirect to new location by Recursion itself when it is 301,307,308 | ||
String newUrl = exitCode.getHeaderField("Location"); | ||
availableURL(newUrl); | ||
|
||
} | ||
else | ||
{ | ||
System.out.println(RED+"["+exitCode.getResponseCode()+"] "+ host +" - Unknown"+RESET); | ||
} | ||
|
||
}catch (Exception e) { | ||
// response fail, server is not existed | ||
System.out.println(RED+"[599] "+ host +" - Fail" +RESET); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import com.sun.jna.Library; | ||
import com.sun.jna.Native; | ||
|
||
interface Kernel32 extends Library { | ||
|
||
boolean SetConsoleTextAttribute(int h_ConsoleOutput, int u16_Attributes); | ||
|
||
int GetStdHandle(int u32_Device); | ||
|
||
} | ||
|
||
public class UrlCheckForWindow { | ||
|
||
// text for window | ||
static final int GRAY = 0x7; | ||
static final int GREEN = 0xA; | ||
static final int RED = 0xC; | ||
static final int WHITE = 0xF; | ||
static final int BLUE = 0x9; | ||
static final int STD_OUTPUT_HANDLE = -11; | ||
|
||
// request url and check the response | ||
public static void availableURL(String host) | ||
{ | ||
Kernel32 lib = Native.load("kernel32", Kernel32.class); | ||
|
||
try { | ||
// request url | ||
URL url = new URL(host); | ||
URLConnection con; | ||
con = url.openConnection(); | ||
|
||
// response | ||
HttpURLConnection exitCode = (HttpURLConnection) con; | ||
exitCode.setInstanceFollowRedirects(true); | ||
HttpURLConnection.setFollowRedirects(true); | ||
exitCode.setConnectTimeout(1000); | ||
|
||
|
||
// response code result | ||
if(exitCode.getResponseCode() >= 200 && exitCode.getResponseCode() < 300) | ||
{ | ||
|
||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), GREEN); | ||
System.out.println("["+exitCode.getResponseCode()+"] "+ host +" - Good"); | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), WHITE); | ||
} | ||
else if(exitCode.getResponseCode() >= 400 && exitCode.getResponseCode() < 500) | ||
{ | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), RED); | ||
System.out.println("["+exitCode.getResponseCode()+"] "+ host +" - Bad"); | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), WHITE); | ||
} | ||
else if(exitCode.getResponseCode() == 301 || exitCode.getResponseCode() == 307 || exitCode.getResponseCode() == 308 ) | ||
{ | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), BLUE); | ||
System.out.println("["+exitCode.getResponseCode()+"] "+ host +" - Redirect"); | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), WHITE); | ||
|
||
// redirect to new location by Recursion itself when it is 301,307,308 | ||
String newUrl = exitCode.getHeaderField("Location"); | ||
availableURL(newUrl); | ||
|
||
} | ||
else | ||
{ | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), GRAY); | ||
System.out.println("["+exitCode.getResponseCode()+"] "+ host +" - Unknown"); | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), WHITE); | ||
} | ||
|
||
}catch (Exception e) { | ||
// response fail, server is not existed | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), RED); | ||
System.out.println("[599] "+ host +" - Fail" ); | ||
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), WHITE); | ||
} | ||
} | ||
} |