我正在用java开发一个网络钓鱼扫描器

我正在用java开发一个网络钓鱼扫描器,java,Java,但我似乎不太明白问题出在哪里。任务要求我创建一个网络钓鱼扫描器,根据我对其在网络钓鱼邮件中的可能性的估计,为每个扫描器分配一个点值。编写一个应用程序,扫描文件或文本中的术语和短语。对于文本文件中出现的每个关键字或短语,为该单词或短语的总分添加指定的分值。对于找到的每个关键字或短语,输出一行单词或短语、出现次数和总分。然后显示整个消息的总分 这就是我目前所拥有的 import java.io.File; import java.util.Scanner; public class Phishin

但我似乎不太明白问题出在哪里。任务要求我创建一个网络钓鱼扫描器,根据我对其在网络钓鱼邮件中的可能性的估计,为每个扫描器分配一个点值。编写一个应用程序,扫描文件或文本中的术语和短语。对于文本文件中出现的每个关键字或短语,为该单词或短语的总分添加指定的分值。对于找到的每个关键字或短语,输出一行单词或短语、出现次数和总分。然后显示整个消息的总分

这就是我目前所拥有的

import java.io.File;
import java.util.Scanner;

public class PhishingScanner {

// list of phishing words
private static final String[] phishingWords = { "DHL", "official",
        "bank", "security", "urgent", "alert", "important", "delivery",
        "ebay", "taxes", "credit", "verify", "confirm", "account",
        "bill", "immediately", "address", "telephone", "ssn", "charity",
        "check", "personal", "confidential", "atm", "warning",
        "fraud", "won", "irs", "owe", "pay" };

// parallel array of point values
private static final int phishingPoints[] = { 2, 2, 1, 1, 1, 1, 1, 2, 3, 3,
        3, 1, 1, 1, 1, 1, 2, 2, 3, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1 };

public static void main(String[] args) throws Exception {
    String fileName = args[0].toString();
    Scanner file = new Scanner(new File(fileName));

    int size = phishingWords.length;
    int wordsCount[] = new int[size];

    for (int i = 0; i < size; i++)
        wordsCount[i] = 0;

    while (file.hasNext()) {
        String word = file.next();

        for (int i = 0; i < size; i++)
            if (word.equalsIgnoreCase(phishingWords[i]))
                wordsCount[i]++;
    }

    System.out.println("\nWord\t\t\tCount\tPoints\n");
    int totalPoints = 0;
    for (int i = 0; i < size; i++) {
        if (wordsCount[i] > 0) {
            System.out.printf("%-15s %8d %8d\n", phishingWords[i],
                    wordsCount[i], phishingPoints[i]);               
            totalPoints += phishingPoints[i] * wordsCount[i];
        }
    }
    System.out.println("\nTotal points: " + totalPoints);
    file.close();
}

}    
这是哪条线

        String fileName = args[0].toString();

要防止在代码中引发未经检查的异常(如ArrayIndexOutOfBoundsException),请尝试添加一些异常处理。在下面的代码中,程序的所有逻辑都被try块包围。如果抛出运行时异常,程序将向用户输出有关如何执行程序的一些信息,然后退出。当将实际文件作为参数传递给程序时,该程序似乎也捕捉到了网络钓鱼欺诈中需要注意的特定词语0

有些人可能会说,您不应该尝试捕获运行时异常,如ArrayIndexOutOfBoundsExceptions,他们可能是对的,但在这种情况下,由于它不是简单地被忽略,我认为它是合适的D

谢谢分享这段代码。这实际上是一个非常有用的程序

最新答复:

 import java.io.File;
 import java.util.Scanner;

 public class PhishingScanner {

 // list of phishing words
 private static final String[] phishingWords = { "DHL", "official",
    "bank", "security", "urgent", "alert", "important", "delivery",
    "ebay", "taxes", "credit", "verify", "confirm", "account",
    "bill", "immediately", "address", "telephone", "ssn", "charity",
    "check", "personal", "confidential", "atm", "warning",
    "fraud", "won", "irs", "owe", "pay" };

  // parallel array of point values
 private static final int phishingPoints[] = { 2, 2, 1, 1, 1, 1, 1, 2, 3, 3,
    3, 1, 1, 1, 1, 1, 2, 2, 3, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1 };

public static void main(String[] args) throws Exception {

try { 
    String fileName = args[0].toString();
    Scanner file = new Scanner(new File(fileName));

    int size = phishingWords.length;
    int wordsCount[] = new int[size];

for (int i = 0; i < size; i++)
    wordsCount[i] = 0;

while (file.hasNext()) {
    String word = file.next();

    for (int i = 0; i < size; i++)
        if (word.equalsIgnoreCase(phishingWords[i]))
            wordsCount[i]++;
}

System.out.println("\nWord\t\t\tCount\tPoints\n");
int totalPoints = 0;
for (int i = 0; i < size; i++) {
    if (wordsCount[i] > 0) {
        System.out.printf("%-15s %8d %8d\n", phishingWords[i],
                wordsCount[i], phishingPoints[i]);               
        totalPoints += phishingPoints[i] * wordsCount[i];
    }
}
System.out.println("\nTotal points: " + totalPoints);
file.close();


} catch(Exception e) { 
     System.out.println("Please enter a file when running the program"); 
  System.out.println("Example: java PhishingScanner EmailFromMom.txt");

}
}//end method main

 }    
导入java.io.File;
导入java.util.Scanner;
公共类网络钓鱼扫描程序{
//网络钓鱼词语列表
私有静态最终字符串[]phishingWords={“DHL”,“official”,
“银行”、“安全”、“紧急”、“警报”、“重要”、“交付”,
“易趣”、“税务”、“信用”、“验证”、“确认”、“账户”,
“账单”、“立即”、“地址”、“电话”、“ssn”、“慈善机构”,
“支票”、“个人”、“机密”、“自动取款机”、“警告”,
“欺诈”、“赢”、“国税局”、“欠”、“付”};
//并行点值数组
私有静态final int-phishingPoints[]={2,2,1,1,1,1,2,3,
3, 1, 1, 1, 1, 1, 2, 2, 3, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1 };
公共静态void main(字符串[]args)引发异常{
试试{
字符串文件名=args[0]。toString();
扫描仪文件=新扫描仪(新文件(文件名));
int size=phishingWords.length;
int-wordscont[]=新的int[size];
对于(int i=0;i0){
System.out.printf(“%-15s%8d%8d\n”),phishingWords[i],
wordsCount[i]、phishingPoints[i];
totalPoints+=phishingPoints[i]*wordsCount[i];
}
}
System.out.println(“\n总分:“+totalPoints”);
file.close();
}捕获(例外e){
System.out.println(“运行程序时请输入文件”);
println(“示例:JavaPhishingScannerEmailFromMom.txt”);
}
}//结束方法主
}    

运行程序时,您需要将文件名作为参数传递给main。我不确定@zouzou是什么意思。您认为
String filename=args[0].toString()是什么?(还要注意,对
字符串
调用
toString
是无用的)如果不传入参数,则args[0]不存在。我创建了一个名为phishwords.txt的文本文件,其中包含30个单词和短语。但是我没有把它放进我的代码中,因为我不知道把它放在哪里。这就是原因吗?@user3255176哦,哇。我只是在我的系统上运行了这个程序,发现了一些错误。我修正了密码。请查看上面的更新。这在我的文件系统上工作。谢谢分享这个源代码。这是一个很酷的节目人。让我知道它是如何为你工作的DMaybe我应该多解释一下程序应该做什么。当我运行它时,我会得到“请在运行程序时输入一个文件…”我会为您发布图片you@user3255176您需要向程序传递一个文件才能正常工作:D为此,在您喜爱的文本编辑器中创建某种文本文件,其中包含一些测试词,并将其与程序放在同一目录中。将此测试文件命名为test.txt,然后像这样运行程序:
java-PhishingScanner-test.txt
 import java.io.File;
 import java.util.Scanner;

 public class PhishingScanner {

 // list of phishing words
 private static final String[] phishingWords = { "DHL", "official",
    "bank", "security", "urgent", "alert", "important", "delivery",
    "ebay", "taxes", "credit", "verify", "confirm", "account",
    "bill", "immediately", "address", "telephone", "ssn", "charity",
    "check", "personal", "confidential", "atm", "warning",
    "fraud", "won", "irs", "owe", "pay" };

  // parallel array of point values
 private static final int phishingPoints[] = { 2, 2, 1, 1, 1, 1, 1, 2, 3, 3,
    3, 1, 1, 1, 1, 1, 2, 2, 3, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1 };

public static void main(String[] args) throws Exception {

try { 
    String fileName = args[0].toString();
    Scanner file = new Scanner(new File(fileName));

    int size = phishingWords.length;
    int wordsCount[] = new int[size];

for (int i = 0; i < size; i++)
    wordsCount[i] = 0;

while (file.hasNext()) {
    String word = file.next();

    for (int i = 0; i < size; i++)
        if (word.equalsIgnoreCase(phishingWords[i]))
            wordsCount[i]++;
}

System.out.println("\nWord\t\t\tCount\tPoints\n");
int totalPoints = 0;
for (int i = 0; i < size; i++) {
    if (wordsCount[i] > 0) {
        System.out.printf("%-15s %8d %8d\n", phishingWords[i],
                wordsCount[i], phishingPoints[i]);               
        totalPoints += phishingPoints[i] * wordsCount[i];
    }
}
System.out.println("\nTotal points: " + totalPoints);
file.close();


} catch(Exception e) { 
     System.out.println("Please enter a file when running the program"); 
  System.out.println("Example: java PhishingScanner EmailFromMom.txt");

}
}//end method main

 }