import java.net.*;
import java.io.*;
import java.text.*;
public class SocketTest
{
public static int[] num={0,0,0};
public static void main(String[] args)
{
try{
BufferedReader is=new BufferedReader(new FileReader("serverlist.txt"));
String server;
String format = "%1$-25s%2$-48s";
System.out.format(format,"网址","服务器信息");
System.out.println("===========================================================");
while ((server = is.readLine()) != null) {
ShowServerInfo(server.trim(),80);
}
System.out.println("===========================================================");
System.out.println("Apache:"+num[0]+",比例 "+NumberFormat.getPercentInstance().format(num[0]*1.0/(num[0]+num[1]+num[2])));
System.out.println("IIS:"+num[1]+",比例 "+NumberFormat.getPercentInstance().format(num[1]*1.0/(num[0]+num[1]+num[2])));
System.out.println("Other:"+num[2]+",比例 "+NumberFormat.getPercentInstance().format(num[2]*1.0/(num[0]+num[1]+num[2])));
is.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
public static void ShowServerInfo(String server,int port){
try{
Socket sc=new Socket(server,port);
StringBuffer sb=new StringBuffer();
sb.append("HEAD / HTTP/1.1\n");
sb.append("Accept: */* \n");
sb.append("Host: "+server+"\n");
sb.append("Connection: Keep-Alive \n\n");
sc.getOutputStream().write(sb.toString().getBytes());
BufferedReader in=new BufferedReader(new InputStreamReader(sc.getInputStream()));
String userInput;
String format = "%1$-25s%2$-54s\n";
while ((userInput = in.readLine()) != null) {
if(userInput.startsWith("Server:")){
if(userInput.length()>55) userInput=userInput.substring(0,54);
if(userInput.toUpperCase().indexOf("APACHE")>=0) num[0]+=1;
else if(userInput.indexOf("IIS")>0) num[1]+=1;
else num[2]+=1;
break;
}
}
sc.getOutputStream().close();
in.close();
sc.close();
}catch(Exception ex){
System.out.println("Err:"+server+","+ex.getMessage());
}
}
}
编译后在CLASS文件同目录下写入serverlist.txt
格式:
www.ppsing.com
www.google.com
gmail.google.com
分享到:
- 2007-12-21 14:18
- 浏览 1026
- 评论(0)
- 论坛回复 / 浏览 (0 / 1455)
- 查看更多
相关推荐
Configuring Some Common Web Servers O'Reilly's WebSite H NCSA httpd H Apache H G Examining Some Other File- and Site-Administration Issues G From Here G Chapter 11 Database Interaction ...
Please do not post any solutions on a publicly-available Web site. We’ll be happy to provide a copy (up-to-date) of this solution manual ourselves to anyone who asks. Acknowledgments: Over the ...
we cover two basic web services to get our feet wet — XML-RPC and REST. The Internet UPC database is an XML-RPC-based service, while Amazon uses REST. Preface [ 2 ] We will create code to call XML-...
[2] , ranging from web servers to games, programming languages and most of the application types that are in use on modern computers. Ports will be discussed further in the section The Ports ...
Don't forget to mention your name, street address, EMail and web site. Contributions: -------------- ICS has been designed by Fran鏾is PIETTE but many other peoples are working on the components ...
chatserv.zip Server side of an internet chat program<END><br>10 , hlink.zip Is a control that you can use to link your program to a web site.<END><br>11 , Popmail.zip Checks your email!...
* Provides code for all example programs via a companion Web site to let the reader see the important objects and methods in context and to understand the purpose of each line of code.
- Updated Level 2 and Level 3 CPU cache information for newer Intel CPU's. - Updated the detection of Hyperthreading and the number of logical CPUs for a new Intel CPU. Release 5.3 build 1025 WIN32...
On production servers, 4096 bytes is a good setting for performance ; reasons. ; Note: Output buffering can also be controlled via Output Buffering Control ; functions. ; Possible Values: ; On = ...
This could be a security risk for your site. 有些时候,由于某种原因,你的目录里没有index文件,这意味着当有人在浏览器地址栏键入了该目录的路径,该目录下所有的文件都会显示出来,这会给你的网站留下安全...
This means, you have to register MSADODAC for each developer, but not for each user of application you have developed!Moreover, MSADODAC has Site License licensing option. So, if developers amount of...
For each port in the list, information about the process that opened the port is also displayed, including the process name, full path of the process, version information of the process (product name...
At that site you'll find up-to-date information regarding the book, a list of errata, and information about other projects that I'm working on. Later this year, I plan to post a brand new chapter on ...
Please don抰 forget this is your private copy for your personal use only. If you require a site license or want to use our technology to distribute pre-configured systems then you need to obtain the...
At that site you'll find up-to-date information regarding the book, a list of errata, and information about other projects that I'm working on. Later this year, I plan to post a brand new chapter on ...
See the CMS web site for // a full list of configuration options. // // http://activemq.apache.org/cms/ // // Wire Format Options: // ========================= // Use either stomp or openwire,...