import java.net.ConnectException;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.HttpURLConnection;
import java.net.UnknownHostException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
public class serverStat {
private static String urlString;
private static File serverNameFile = new File("server.ini");
public static void main(String[] args) {
if (args.length != 1) {
getServerName(getServerNameFile());
System.exit(0);
}
setUrlstring(args[0]);
connect(urlString);
}
private static void getServerName(File f) {
// File f = new File("server.ini");
FileReader fr = null;
try {
fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String Line = new String();
while (Line != null) {
Line = Line.trim();
if (Line.startsWith("#") || Line.equals("")) {
} else {
serverStat.setUrlstring(Line);
connect(urlString);
}
Line = br.readLine();
}
br.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void connect(String urlarg) {
try {
URL url = new URL(urlarg);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
System.out.println(connection.getResponseCode());
System.out.println(connection.getResponseMessage());
System.out.println("*** Success ***");
} catch (MalformedURLException e) {
System.out.println("*** Exception *** " + e);
} catch (UnknownHostException e) {
System.out.println("*** Exception *** " + e);
} catch (ConnectException e) {
System.out.println("*** Exception *** " + e);
} catch (IOException e) {
System.out.println("*** Exception *** " + e);
}
}
public static String getUrlstring() {
return urlString;
}
public static void setUrlstring(String args) {
args = args.toLowerCase();
if (args.startsWith("http://")) {
} else {
args = "http://" + args;
}
System.out.println(args);
serverStat.urlString = args;
}
public static File getServerNameFile() {
return serverNameFile;
}
public static void setServerNameFile(File serverNameFile) {
if (serverNameFile.exists()) {
serverStat.serverNameFile = serverNameFile;
} else {
serverStat.serverNameFile = new File("server.ini");
}
}
}
2007年5月22日星期二
HTTP服务返回值判定程序
经常在客户系统里判定IBMIHS的状况,但是服务器需要重重防火墙和映射地址才能访问。于是写了一个程序,目的是放到一个服务器里用来便可以判断所有同一网段的HTTP返回值是否正常,以便简化检查的手工劳动 ::D
订阅:
博文评论 (Atom)
没有评论:
发表评论