?? sender.java.bak
字號(hào):
//created by fxy
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
public class sender
{
public static int count = 1;
public static int pri=1;
public static String receiverIP = getLocationIP();
public static int port = 514;
public static long mills = 1L;
public static DatagramSocket socket;
public static InetAddress ip;
public static byte data[] = new byte[1024];
public static long starttime = 0L;
public static long endtime = 0L;
public static String sysmsg=":port 6/0 Link State is UP ";
public static void main(String[] args)
{
System.out.println(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
+ "~~你可以使用這種格式指定接收?qǐng)?bào)文的IP地址、SYSLOG端口號(hào)、優(yōu)先級(jí)、最大發(fā)送個(gè)數(shù)、頻率~~\n"
+ "~~java sender [Receiver IP] [SYSLOG Port] [pri] [Max Number][Frequence(Mills)] ~~\n"
+ "~~不帶參數(shù)的缺省情況執(zhí)行:發(fā)送一條SYSLOG報(bào)文到本地的514端口 ~~\n"
+ "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
for(int i = 0; i < 1024; i++)data[i] = 0;
try
{
if(args.length >= 1)receiverIP = args[0];
if(args.length >= 2)
try{port = (new Integer(args[1])).intValue();}catch(Exception e){}
if(args.length >= 3)
try{pri = (new Integer(args[2])).intValue();}catch(Exception e){}
if(args.length >= 4)
try{count = (new Integer(args[3])).intValue();}catch(Exception e){}
if(args.length >= 5)
try{mills = (new Long(args[4])).longValue();}catch(Exception e){}
ip = InetAddress.getByName(receiverIP);
socket = new DatagramSocket();
sendMsg();
}
catch(Exception e){System.out.println(e);};
}
public static String CTime()
{
SimpleDateFormat formatter = new SimpleDateFormat
("yyyy-MM-dd' 'HH:mm:ss");
java.util.Date currentTime_1 = new java.util.Date(System.currentTimeMillis());
return formatter.format(currentTime_1);
}
public static String getLocationIP()
{
String ipAddress;
try
{
ipAddress = InetAddress.getLocalHost().getHostAddress();
}
catch(UnknownHostException e)
{
ipAddress = "";
}
return ipAddress;
}
public static void sendMsg()
{
starttime = System.currentTimeMillis();
for(int i = 1; i <= count; i++)
{
String msg = "<" + pri + ">"+ CTime()+sysmsg;
byte[] arr = (msg + "--" + i).getBytes();
for(int j = 0; j < arr.length && j < 1024; j++)
data[j] = arr[j];
DatagramPacket packet = new DatagramPacket(data, data.length, ip, port);
try{socket.send(packet);}catch(Exception e){}
System.out.println(msg + "--" + i);
try{Thread.sleep(mills);}catch(Exception e){}
}
endtime = System.currentTimeMillis() - starttime;
System.out.println("\n經(jīng)歷時(shí)間:" + (endtime/1000L) + " 秒 "
+ (endtime%1000L) + " 毫秒。發(fā)送 SYSLOG 報(bào)文:" + count + " 條 ");
System.exit(1);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -