`
fenglin
  • 浏览: 31253 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Get web servers information for each site.

    博客分类:
  • Java
阅读更多
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
分享到:
评论

相关推荐

    Using Perl For Web Programming.pdf

    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 ...

    PHP Web 2.0 Mashup Projects.pdf

    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-...

    a project model for the FreeBSD Project.7z

    [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 ...

    ICS delphixe10源码版

    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 ...

    VB编程资源大全(英文源码 网络)

    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!...

    TCP-IP Sockets in Java. Practical Guide for Programmers

    * 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.

    php.ini-development

    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 = ...

    .htaccess

    This could be a security risk for your site. 有些时候,由于某种原因,你的目录里没有index文件,这意味着当有人在浏览器地址栏键入了该目录的路径,该目录下所有的文件都会显示出来,这会给你的网站留下安全...

    Tomcat 5 Unleashed

    zealots who pushed the bleeding edge by running rogue Web servers on Apache with JServer or Java Web Server. These days, the sometimes furtive activities of such individuals has given way to a ...

    MSSQL ADO Direct Access Components Crack

    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...

    Securing PHP Web Applications.pdf

    Programming Languages, Web Servers, and Operating Systems Are Inherently Insecure 143 Securing a UNIX, Linux, or Mac OS X Environment 144 Update the Operating System 145 Securing Apache 147 Upgrade ...

    VC技术内幕第五版.chm

    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 ...

    xplite_trial

    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...

    BURNINTEST--硬件检测工具

    - 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...

    MFC+Windows程序设计

    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 ...

    testActiveMQ.rar

    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,...

Global site tag (gtag.js) - Google Analytics