私は、(別のクラスのmainメソッドからの)IPアドレスを受け取り、それが行くにつれてそれぞれにpingする一連のIPアドレスをループするコードを作成しました。私はこれにGUIのフロントエンドがあり、クラッシュしていました(なぜ私はマルチスレッドをやったのですか)。私の問題は、呼び出し可能なコードとして私のpingコードの引数としてIPアドレスを取ることができなくなります。これを行う方法を見つけることができないようです。呼び出し可能なメソッドが引数を取る方法はありますか?そうでない場合は、私がしようとしていることを達成するための方法はありませんか?呼び出し可能なメソッドで引数を取る方法はありますか?
コード:
public class doPing implements Callable<String>{
public String call() throws Exception{
String pingOutput = null;
//gets IP address and places into new IP object
InetAddress IPAddress = InetAddress.getByName(IPtoPing);
//finds if IP is reachable or not. a timeout timer of 3000 milliseconds is set.
//Results can vary depending on permissions so cmd method of doing this has also been added as backup
boolean reachable = IPAddress.isReachable(1400);
if (reachable){
pingOutput = IPtoPing + " is reachable.\n";
}else{
//runs ping command once on the IP address in CMD
Process ping = Runtime.getRuntime().exec("ping " + IPtoPing + " -n 1 -w 300");
//reads input from command line
BufferedReader in = new BufferedReader(new InputStreamReader(ping.getInputStream()));
String line;
int lineCount = 0;
while ((line = in.readLine()) != null) {
//increase line count to find part of command prompt output that we want
lineCount++;
//when line count is 3 print result
if (lineCount == 3){
pingOutput = "Ping to " + IPtoPing + ": " + line + "\n";
}
}
}
return pingOutput;
}
}
IPtoPingが撮影された引数にするために使用
ので....これは動作しません。引数の配列に対して渡されました... – Michael
これはステートメントまたは質問として意図されていますか?いずれにしても、あなたが何を言っているのかわからない。 –