public static long calSpeed(String ip) {
Runtime runtime = Runtime.getRuntime(); // 获取当前程序的运行进对象
Process process = null; // 声明处理类对象
String line = null; // 返回行信息
InputStream is = null; // 输入流
InputStreamReader isr = null; // 字节流
BufferedReader br = null;
try {
process = runtime.exec("ping " + ip +" -w 1000"); // PING
is = process.getInputStream(); // 实例化输入流
isr = new InputStreamReader(is);// 把输入流转换成字节流
br = new BufferedReader(isr);// 从字节中读取文本
while ((line = br.readLine()) != null) {
if (line.contains("TTL")) {
int begin = line.indexOf("TTL=");
String value = line.substring(begin+4,line.length());
return Integer.valueOf(value);
}
}
} catch (IOException e) {
System.out.println(e);
runtime.exit(1);
}finally{
if(is!=null){
try {
is.close();
} catch (IOException e) {
}
}
if(isr!=null){
try {
isr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(br!=null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return 10000;
}

java 测试IP的更多相关文章

  1. 如何使用 Java 测试 IBM Systems Director 的 REST API

    转自: http://www.ibm.com/developerworks/cn/aix/library/au-aix-systemsdirector/section2.html 如何使用 Java ...

  2. Java 根据IP获取地址

    用淘宝接口:(源码:java 根据IP地址获取地理位置) pom.xml: <!-- https://mvnrepository.com/artifact/net.sourceforge.jre ...

  3. Java测试工具

    1.   开源测试工具: http://www.open-open.com/43.htm 2.   10款常用的JAVA测试工具 :http://developer.51cto.com/art/200 ...

  4. 在Jmeter中使用自定义编写的Java测试代码

    我们在做性能测试时,有时需要自己编写测试脚本,很多测试工具都支持自定义编写测试脚本,比如LoadRunner就有很多自定义脚本的协议,比如"C Vuser","Java ...

  5. Java根据ip地址获取Mac地址,Java获取Mac地址

    Java根据ip地址获取Mac地址,Java获取Mac地址 >>>>>>>>>>>>>>>>>&g ...

  6. Java获取ip地址的几种方法

    以下内容介绍下java获取ip地址的几种思路. 1.直接利用java.net.InetAddress类获取,不过这种方法只在windows环境下有效,在linux环境下只能获取localhost地址( ...

  7. 用fiddler测试ip轮询

    测试业务: 服务端根据域名配置了三台服务器ip,测试ip轮询的逻辑 测试方法: 使用fiddler配置hosts即可 1.1.1.1 第一台ip 1.1.1.1 第二台ip 1.1.1.1 第三台ip ...

  8. Vultr VPS测试IP $5/月KVM-512MB/15G SSD/1T

    vultr主要卖点是:SSD硬盘.超低价格.全球13个机房.10Gb服务器带宽.3GHz CPU.性能优异.vultr vps详细评测可参考这篇文章. 以下是vutlr vps官方提供的测试IP地址: ...

  9. Java将ip字符串转换成整数的代码

    下面代码是关于Java将ip字符串转换成整数的代码,希望对各位有较大用途. public class IpUtil { public static int Ip2Int(String strIp){ ...

随机推荐

  1. Win7下配置Django+Apache+mod_wsgi+Sqlite

    搭建环境: win7 64位 Django 1.8.5 Apache2.4.17 mod_wsgi_ap24py27.so Python2.7.9 1 安装Apache 下载Apache Haus版, ...

  2. Light OJ - 1058 Parallelogram Counting(判定平行四边形)

    Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...

  3. 解决 Oracle 11g 不能导出空表的问题

    --解决 Oracle 11g 不能导出空表的问题 --执行下面语句,查询数据库中的空表,同时产生分配空间.把生成的结果复制出来并执行. select 'alter table '||table_na ...

  4. 解决Android Studio Gradle Build特别慢的问题

    解决Android Studio Gradle Build 特别慢的问题 C:\Users\你的用户名\.gradle目录下新建一个文件名为gradle.properties的文件.内容为:org.g ...

  5. 剑指offer 调整数组顺序使得奇数位于偶数前面

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 class Solution { public:     void  ...

  6. ftok函数的使用

    ftok函数的定义:系统建立IPC通讯 (消息队列.信号量和共享内存) 时必须指定一个ID值.通常情况下,该id值通过ftok函数得到. 头文件 #include <sys/types.h> ...

  7. PAT (Advanced Level) 1040. Longest Symmetric String (25)

    暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ...

  8. Bessie Goes Moo

    Bessie Goes Moo 题目描述 Farmer John and Bessie the cow love to exchange math puzzles in their free time ...

  9. BNU OJ 50997 BQG's Programming Contest

    #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...

  10. xtrabackup数据库备份

    xtrabackup备份 一.Xtrabackup概述 1.1.简介 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Ho ...