62,623
社区成员
发帖
与我相关
我的任务
分享import javax.swing.Timer;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.*;
import java.io.*;
public class Test {
Timer time = null;
public Test() {
time=new Timer(2000, new TimeAction());
time.setInitialDelay(0);
time.start();
}
public static void main(String[] args) throws Exception {
// for(int i = 1025; i<1036;i++){
Socket sk=new Socket("10.193.139.7",1048);
if(sk!=null)
System.out.println("ok!");
BufferedReader read=new BufferedReader(new InputStreamReader(sk.getInputStream()));
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(sk.getOutputStream()));
System.out.println(read.readLine());
writer.write("free"+"\n");
writer.flush();
System.out.println(read.readLine());
writer.write("123"+"\n");
writer.flush();
System.out.println(read.readLine());
writer.write("stop\n");
writer.flush();
System.out.println(read.readLine());
read.close();
writer.close();
sk.close();
// }
}import javax.swing.Timer;
import java.io.*;
import java.net.*;
import java.util.*;
public class Portsniff {
public static void main(String[] args) {
// Create application frame.
//PortsniffFrame frame = new PortsniffFrame();
// Show frame
// frame.setVisible(true);
String ip="127.0.0.1";
String hostname=new String();
try{
InetAddress address = InetAddress.getByName(ip);
hostname=address.getHostName();
}
catch(UnknownHostException e){
System.out.println("Could not find "+ ip);
}
//////接下来开始嗅
for(int nport=1;nport<=60;nport++)
{
try{
Socket s=new Socket(hostname,nport);
System.out.println("The port "+ nport+"is open");
}
catch(IOException e){
System.out.println("The port"+nport+" is closed");
}
}
}
}
import java.io.*;
import java.net.*;
public class PortScanner {
public static void main(String[] args) {
Socket s = null;
for (int port = 0; port < 1024; port++) {
try {
s = new Socket("localhost", port);
System.out.println("There is a server on port " + port);
} catch (IOException e) {
System.out.println("Can't connect to port " + port);
}finally {
try {
if(s != null) s.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}
}
}