Skip to content

Commit

Permalink
issue-10 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunbee Kim committed Oct 6, 2020
1 parent f84d593 commit 685bb8a
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 9 deletions.
Binary file added bin/ConvertJavaToJson.class
Binary file not shown.
Binary file added bin/UrlCheck$1.class
Binary file not shown.
Binary file modified bin/UrlCheck.class
Binary file not shown.
Binary file added bin/UrlCheckForMac.class
Binary file not shown.
Binary file added bin/UrlCheckForWindow.class
Binary file not shown.
Binary file modified bin/mac/UrlCheck.jar
Binary file not shown.
Binary file modified bin/window/UrlCheck.exe
Binary file not shown.
Binary file modified bin/window/UrlCheck.jar
Binary file not shown.
18 changes: 16 additions & 2 deletions src/UrlCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class UrlCheck {

static JSONArray list = new JSONArray();

static int Bad = 0;

public static void helpMessage()
{
System.out.println("========================================================");
Expand Down Expand Up @@ -110,6 +112,8 @@ public static void endMessage()
{

System.out.println("========================================================");
System.out.println("End Code : " + Bad);
System.out.println("========================================================");
}


Expand Down Expand Up @@ -150,6 +154,10 @@ public static void fileUrlListUp(String fName, boolean archived, boolean secured
{
JSONObject temp = new JSONObject();
temp = ConvertJavaToJson.availableURL(str);
if((int)temp.get("status") < 200 || (int)temp.get("status") >= 400)
{
Bad++;
}
list.add(temp);
}
else
Expand All @@ -159,11 +167,17 @@ public static void fileUrlListUp(String fName, boolean archived, boolean secured

if(runMac)
{
UrlCheckForMac.availableURL(str);
if(!UrlCheckForMac.availableURL(str))
{
Bad++;
}
}
else
{
UrlCheckForWindow.availableURL(str);
if(!UrlCheckForWindow.availableURL(str))
{
Bad++;
}
}
}
// request archived
Expand Down
10 changes: 6 additions & 4 deletions src/UrlCheckForMac.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public class UrlCheckForMac {
public static final String RESET = "\033[0m";

// request url and check the response
public static void availableURL(String host)
public static boolean availableURL(String host)
{

boolean result = false;

try {
// request url
URL url = new URL(host);
Expand All @@ -31,7 +32,7 @@ public static void availableURL(String host)
// // for Mac
if(exitCode.getResponseCode() >= 200 && exitCode.getResponseCode() < 300)
{

result = true;
System.out.println(GREEN+"["+exitCode.getResponseCode()+"] "+ host +" - Good"+RESET);

}
Expand All @@ -45,7 +46,7 @@ else if(exitCode.getResponseCode() == 301 || exitCode.getResponseCode() == 307 |

// redirect to new location by Recursion itself when it is 301,307,308
String newUrl = exitCode.getHeaderField("Location");
availableURL(newUrl);
result = availableURL(newUrl);

}
else
Expand All @@ -58,5 +59,6 @@ else if(exitCode.getResponseCode() == 301 || exitCode.getResponseCode() == 307 |
System.out.println(RED+"[599] "+ host +" - Fail" +RESET);

}
return result;
}
}
9 changes: 6 additions & 3 deletions src/UrlCheckForWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public class UrlCheckForWindow {
static final int STD_OUTPUT_HANDLE = -11;

// request url and check the response
public static void availableURL(String host)
public static boolean availableURL(String host)
{
boolean result = false;

Kernel32 lib = Native.load("kernel32", Kernel32.class);

try {
Expand All @@ -43,7 +45,7 @@ public static void availableURL(String host)
// response code result
if(exitCode.getResponseCode() >= 200 && exitCode.getResponseCode() < 300)
{

result = true;
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), GREEN);
System.out.println("["+exitCode.getResponseCode()+"] "+ host +" - Good");
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), WHITE);
Expand All @@ -62,7 +64,7 @@ else if(exitCode.getResponseCode() == 301 || exitCode.getResponseCode() == 307 |

// redirect to new location by Recursion itself when it is 301,307,308
String newUrl = exitCode.getHeaderField("Location");
availableURL(newUrl);
result = availableURL(newUrl);

}
else
Expand All @@ -78,5 +80,6 @@ else if(exitCode.getResponseCode() == 301 || exitCode.getResponseCode() == 307 |
System.out.println("[599] "+ host +" - Fail" );
lib.SetConsoleTextAttribute(lib.GetStdHandle(STD_OUTPUT_HANDLE), WHITE);
}
return result;
}
}

0 comments on commit 685bb8a

Please sign in to comment.