1.文本分析工具
由于曾經在網路安全上有過學習,所以對日志的查看尤為重要
怎樣在大批的資料中篩選出自己想要的資料呢,我搜索了好多工具,很難滿足自己特定的需求
于是我決定自己撰寫一個程式,來篩選
這是一個大小只有10KB的程式,但是功能卻不小
與其他同類成熟的工具的相比,有以下優點:
1:可以批量分析文本,只需要把所有檔案集中到一個檔案夾中即可
2:支持1000個自定義規則的保存,在再次啟動時無需重新輸入,只需要加載好已經保存的規則即可
3:具有強大的例外處理機制,具有狀態顯示功能
4:具備篩選無窮多字串的功能,只需要以回車符分開即可
其不僅僅能分析日志,也能分析常見的文本,保留有用的內容



當然,還有很多的不足,功能并不是特別的強大
1:只能在安裝有jre運行環境的機器上使用
2:不支持字串模糊匹配的功能
3:功能單一,如果能加入其他功能就更好了,比如替換所有檔案的指定字串
但是僅僅這些我就做了6個小時,尤其是IO的操作,大量的例外隨時出現,經過不斷修改,已經成為非常穩定的程式了
以后有時間的話我會定期去更新,加入更強大的功能,如果有想法的話可以私聊或評論,我會做一些更實用的工具https://study.gengronglin.top/Source/An.zip已發布至服務器,可以免費下載
由于網站采用自簽名SSL證書,訪問可能會提示證書無效或者過期,提示危險,不需要擔心,放心下載即可
package Analysis;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.Arrays;
public class LogAnalysisGUI implements SendClass{
Rule r=new Rule();
LogAnalysisGUI() throws IOException {
JFrames t=new JFrames(this);
}
@Override
public void Do() throws FileNotFoundException {
int i=0,c=0;
for(String Name:Select(new File(r.SelectPath))) {
StringBuilder St = new StringBuilder();
if (Name != null) {
FileInputStream fis = new FileInputStream(r.SelectPath + "\\" + Name);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while (true) {
try {
String s = br.readLine();
if (!s.equals("") && check(s)) {
St.append(s);
St.append("\n");
}
}
catch (Exception e){
break;
}
}
if (!String.valueOf(St).equals("")) {
FileOutputStream fos = new FileOutputStream(r.SelectPath + "\\" + Name.substring(0, Name.lastIndexOf(".")) + r.LastName);
PrintWriter pw = new PrintWriter(fos);
pw.write(String.valueOf(St));
pw.close();
c++;
}
i++;
}
}
JPanels.Message.append("執行成功!共處理了"+i+"個檔案,生成了"+c+"個檔案\n");
}
public static void main(String[] args) throws IOException {
new LogAnalysisGUI();
}
public boolean check(String s) {
for (String a : r.Must) {
try {
if (!s.contains(a)) {
return false;
}
}
catch (Exception e){
JPanels.Message.append(Arrays.toString(e.getStackTrace()) +"A56\n");
}
}
for (String a : r.MustNot) {
if (!a.equals("")&&s.contains(a)) {
return false;
}
}
return true;
}
public String[] Select(File file) {
String T[]=new String[1000];
int i=0;
File[] files = file.listFiles();
assert files != null;
for (File fi : files) {
String s =fi.getName();
if(s.contains(r.SelectFile)){
T[i]=s;
i++;
System.out.println(s);
}
}
return T;
}
@Override
public void Send(Rule r) {
this.r=r;
}
}
class JFrames extends JFrame{
JPanels jp;
JFrames(SendClass sc) throws IOException {
jp=new JPanels(sc);
setTitle("日志分析工具");
setSize(750,750);
setResizable(false);
setDefaultCloseOperation(JFrames.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
add(jp);
setVisible(true);
}
}
class JPanels extends JPanel implements ActionListener {
SendClass sc;
JLabel l1=new JLabel("指定路徑+檔案夾名,絕對路徑或者相對路徑:");
JLabel l2=new JLabel("檔案夾內日志檔案名篩選規則(必須包含的字串,不能非空!):");
JLabel l3=new JLabel("重命名之后的日志擴展名(不要與原檔案擴展名相同):");
JLabel l4=new JLabel("內容行篩選規則(必須包含的字串)以回車符分割多個字串:");
JLabel l5=new JLabel("內容行篩選(必須不包含的字串)以回車符分割多個字串:");
JScrollPane jsp1=new JScrollPane();
JScrollPane jsp2=new JScrollPane();
JScrollPane jsp3=new JScrollPane();
JTextField t1=new JTextField("Test");
JTextField t2=new JTextField(".log");
JTextField t3=new JTextField(".xml");
JTextArea ta1=new JTextArea("");
JTextArea ta2=new JTextArea("");
JButton b1=new JButton("分析并保存檔案在同一檔案夾");
JButton b2=new JButton("保存篩選規則");
JTextField tx=new JTextField("規則1");
JButton b3=new JButton("加載篩選規則");
JComboBox jb=new JComboBox();
static JTextArea Message=new JTextArea("啟動成功!\n");
JPanels(SendClass sc){
this.sc=sc;
setLayout(null);
l1.setBounds(0,0,300,20);
t1.setBounds(0,20,300,20);
l2.setBounds(0,40,300,20);
t2.setBounds(0,60,300,20);
l3.setBounds(0,80,300,20);
t3.setBounds(0,100,300,20);
l4.setBounds(320,0,430,20);
l5.setBounds(320,350,430,20);
b1.setBounds(0,120,300,40);
tx.setBounds(0,170,300,20);
b2.setBounds(0,200,300,40);
jb.setBounds(0,250,300,30);
b3.setBounds(0,290,300,40);
jsp1.setBounds(340,20,380,330);
jsp2.setBounds(340,370,380,330);
jsp3.setBounds(10,350,290,300);
jsp1.getViewport().add(ta1);
jsp2.getViewport().add(ta2);
jsp3.getViewport().add(Message);
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(t1);
add(t2);
add(t3);
add(b1);
add(jsp1);
add(jsp2);
add(jsp3);
add(tx);
add(b2);
add(jb);
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
try {
Load();
}
catch (Exception e){
Message.append(Arrays.toString(e.getStackTrace()) +"A167\n");//167
}
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1){
try {
String Must=ta1.getText();
String MustNot=ta2.getText();
String MustContain=t2.getText();
String Path=t1.getText();
String Name=t3.getText();
String RuleName=tx.getText();
Rule newRule =new Rule();
newRule.name=RuleName;
newRule.Must= Must.split("\n");
newRule.MustNot= MustNot.split("\n");
newRule.SelectFile= MustContain;
newRule.SelectPath= Path;
newRule.LastName=Name;
sc.Send(newRule);
sc.Do();
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
}
}
else if(e.getSource()==b2){
String Must=ta1.getText();
String MustNot=ta2.getText();
String MustContain=t2.getText();
String Path=t1.getText();
String Name=t3.getText();
String RuleName=tx.getText();
Rule newRule =new Rule();
newRule.name=RuleName;
newRule.Must= Must.split("\n");
newRule.MustNot= MustNot.split("\n");
newRule.SelectFile= MustContain;
newRule.SelectPath= Path;
newRule.LastName=Name;
sc.Send(newRule);
if(checkError(newRule)){
try {
SaveRule(newRule);
Message.append("保存成功!\n");
} catch (Exception ex) {
Message.append(Arrays.toString(ex.getStackTrace()) +"A200\n");//200
}
}else{
Message.append("名稱或者路徑不能為空");
}
}
else if(e.getSource()==b3){
try {
Rule s=LoadRule(jb.getSelectedItem().toString());
sc.Send(s);
ta1.setText("");
for(int i=0;i<s.Must.length;i++){
ta1.append(s.Must[i]);
if(i!=s.Must.length-1){ta1.append("\n");}
}
ta2.setText("");
for(int i=0;i<s.MustNot.length;i++){
ta2.append(s.MustNot[i]);
if(i!=s.MustNot.length-1){ta2.append("\n");}
}
t1.setText(s.SelectPath);
t2.setText(s.SelectFile);
t3.setText(s.LastName);
tx.setText(s.name);
Message.append("加載成功!\n");
} catch (Exception ex) {
Message.append(Arrays.toString(ex.getStackTrace()) +"A223\n");//223
}
}
}
private boolean checkError(Rule newRule) {
if(newRule.SelectPath.equals("")){return false;}
return true;
}
public void SaveRule(Rule r) throws IOException{
Rule []A=new Rule[1000];
File f=new File("Rule.sav");
if(!f.exists()){
f.createNewFile();
FileOutputStream fos=new FileOutputStream(f);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(A);
}
FileInputStream fis=new FileInputStream(f);
ObjectInputStream ois=null;
try{
ois=new ObjectInputStream(fis);
}
catch (Exception ex){
Message.append(Arrays.toString(ex.getStackTrace()) +"A246\n");//246
}
try {
A= (Rule[]) ois.readObject();
}
catch (Exception e){
Message.append(Arrays.toString(e.getStackTrace()) +"A252\n");//252
}
for(int i=0;i<1000;i++){
if(A[i] == null || A[i].name.equals(r.name)){
A[i]=r;
break;
}
}
FileOutputStream fos=new FileOutputStream(f);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(A);
Load();
}
public Rule LoadRule(String Name) throws IOException{
File f=new File("Rule.sav");
if(!f.exists()){
f.createNewFile();
Rule []A=new Rule[1000];
FileOutputStream fos=new FileOutputStream(f);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(A);
}
FileInputStream fis=new FileInputStream(f);
ObjectInputStream ois=null;
try{
ois=new ObjectInputStream(fis);
}
catch (Exception ex){
Message.append(Arrays.toString(ex.getStackTrace()) +"A277\n");//277
}
Rule []A=new Rule[1000];
try {
A= (Rule[]) ois.readObject();
}
catch (Exception e){
Message.append(Arrays.toString(e.getStackTrace()) +"A284\n");//284
}
for(Rule x:A){
if(x.name.equals(Name)){
return x;
}
}
return null;
}
public void Load() throws IOException{
File f=new File("Rule.sav");
if(!f.exists()){
f.createNewFile();
Rule []A=new Rule[1000];
FileOutputStream fos=new FileOutputStream(f);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(A);
}
FileInputStream fis=new FileInputStream(f);
ObjectInputStream ois=null;
try{
ois=new ObjectInputStream(fis);
}
catch (Exception ex){
Message.append(Arrays.toString(ex.getStackTrace()) +"A306\n");//306
}
Rule []A=new Rule[1000];
try {
A = (Rule[]) ois.readObject();
}
catch (Exception e){
Message.append(Arrays.toString(e.getStackTrace()) +"A313\n");//313
}
jb.removeAllItems();
for(Rule x:A){
if(x!=null) {
jb.addItem(x.name);
}
}
}
}
class Rule implements Serializable{
String name="";
String[] Must = {};
String[] MustNot = {};
String SelectFile="";
String SelectPath="";
String LastName="";
}
interface SendClass{
void Send(Rule r);
void Do() throws FileNotFoundException;
}
可以參考參考代碼,如果喜歡,請支持原創,并給予鼓勵,包括原始碼,程式,相關檔案僅供個人使用,請勿用于其他用途!
2.模擬鍵盤輸入工具
事實上,這種工具現在有很多很多,甚至自己如果有編程基礎的話,隨隨便便就能用vbs腳本撰寫一個很簡單的程式
我撰寫這個程式的目的呢,
其一是為了學習Java Robot自動化類,以便能夠開發更多實用的工具
其二是想做一個比較專業一點的自動點擊工具,比如vbs腳本不能夠隨時終止,曾經由于輸出大量的回車符,導致電腦徹底卡死,所以我就用了java開發
特點:啟用了3個執行緒,使得既能同時運行程式,又能隨時控制程式的終止,又能隨時查看程式執行進度
也能夠方便的大量發送資訊(哈哈,不建議,可能會被凍結,不要問我怎么知道的)



由于代碼太多,所以這里就不暫時了,想了解的話直接去我服務器網站上下載壓縮包即可,里面包含了jar可執行程式,java原始碼,class編譯后的程式,以及簡單教程
https://study.gengronglin.top/Source/Au.zip
由于網站采用自簽名SSL證書,訪問可能會提示證書無效或者過期,提示危險,不需要擔心,放心下載即可
可以參考參考代碼,如果喜歡,請支持原創,并給予鼓勵,包括原始碼,程式,相關檔案僅供個人使用,請勿用于其他用途!
如果喜歡,請打賞,如果不愿意,下載使用即可,如果有想法可以評論或者私聊
以便激勵我能夠做更多的程式
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/394160.html
標籤:其他
