java调用全网最快端口扫描器

如果需要外部传入参数,可以传入args或者使用  读取配置文件的方式

public class Execute {

    public static void main(String[] args) {
        scan();
    }

    public static void scan(){
        //这段代码为了打成jar包的时候能用=======================
        ResourceLoader resourceLoader=new DefaultResourceLoader();
        Resource resource=resourceLoader.getResource("classpath:s.exe");
        InputStream is=null;
        try {
            is=resource.getInputStream();
            FileOutputStream fos = new FileOutputStream("/D:/tmp/s.exe");
            byte[] b = new byte[1024];
            int length;
            while((length=is.read(b))>0){
                fos.write(b,0,length);
            }
            is.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //================================================================

        Runtime runtime=Runtime.getRuntime();
        BufferedReader stdInput=null;
        BufferedReader stdError=null;
        try {

            Process process = runtime.exec("/D:/tmp/s.exe TCP 192.168.0.1 192.168.0.254 22 50");
            //获取正常输出流
            stdInput= new BufferedReader(
                    new InputStreamReader(process.getInputStream()));
            //获取错误输出流
            stdError = new BufferedReader(
                    new InputStreamReader(process.getErrorStream()));
            System.out.println("output of the command:\n");
            String s = null;
            while ((s = stdInput.readLine()) != null) {
                System.out.println(s);
            }

            System.out.println("error of the command (if any):\n");
            while ((s = stdError.readLine()) != null) {
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (stdInput!=null){
                try {
                    stdInput.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (stdError!=null){
                try {
                    stdError.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值