Question

Create a new NetBeans project (using Ant) titled YourNameExam2P3. 2. Pretend you are a malware author...

Create a new NetBeans project (using Ant) titled YourNameExam2P3.

2. Pretend you are a malware author and you are trying to come up with random-looking web domain names for your command-and-control viruses, e.g. “RDf-45dlfjxg7.com”.

3. First, you need to come up with some original criteria that define your domain name pattern. For example, “it should be 13 characters long, include 3 integers only, no lower case letters, and possibly end in .net or .edu”. You should come up with your own ORIGINAL pattern, of course.

4. Then, write an algorithm that is able to generate a list of random domain names based on your pattern. Make sure you are able to create at least 10 unique domain names.

5. Next, come up with the regex that fits your pattern. When you check the domain names created by your algorithm, they should all be matched by your regex.

6. For the output of your program, you should test your regex against 10 domain names that DO NOT match, as well as 10 domains that were generated by your algorithm and DO match. We should see labels of “Valid” and “Invalid” accordingly, next to each sample domain name.

7. The pattern you come up with is up to you, but at a minimum: a. It should end with at least two possible dot-somethings, e.g. “.com” and “.net”. b. Before the dot, your domain should have at least 10 characters. c. Must include letters, numbers, and possibly dashes, proportion, and pattern up to you.

8. Again, fully comment on your code, and it should be obvious what your program does from the output.

I need my program in Java Programming with fully commented.

Homework Answers

Answer #1

Short Summary:

  • Implemented the program as per the below domain pattern requirement
  • Pattern: The domain name should contain atleast one alphabet and one number and only one hyphen(-), should contain minimum of 14 characters(10 chars before dot)

Source Code:

YourNameExam2P3.java

//This class generates a random domain ans validates it against a regex
public class YourNameExam2P3 {

   public static void main(String[] args)
   {
       //Initialize an end String array
       String [] endStr= {".com",".net",".org"};
       //Set no of characters before DOT as 12
       int n = 12;
       // Form a string with alphabets, numbers and a hyphen
       String sampleStr = "0123456789" + "-"
               + "abcdefghijklmnopqrstuvxyz";
       String[] str=sampleStr.split("");
       // create StringBuffer
       StringBuilder sb = null;

       int noOfDomains=20;
       int validCount=0;
       int invalidCount=0;
       for(int count=0;count<noOfDomains;count++)
       {
           sb = new StringBuilder(n);
           for (int i = 0; i < n; i++) {

               // generate a random number between
               int index = (int)(sampleStr.length() * Math.random());
               //Below condition to make sure hyphen is present only once
               if(sb.toString().contains("-")&&str[index].equals("-"))
               {
                   //decrease i count to make sure another iteration goes to meet string length
                   i--;
               }
               else
               {
                   sb.append(str[index]);
               }
           }
           //This is to choose a random string like .com,.org,.net at last
           int num=(int) (endStr.length*Math.random());

           String generatedDomain=sb.append(endStr[num]).toString();
           //Call to validate domain name against regex
           boolean valid= isValidDomain(generatedDomain);

           //The below if checks are to get 10 valid and invalid domains to display
           if(valid && validCount<10)
           {
               validCount++;
               System.out.println("The domain "+generatedDomain+" is a valid domain"+"\n");
           }
           if(!valid && invalidCount<10)
           {
               invalidCount++;
               System.out.println("The domain "+generatedDomain+" is an invalid domain"+"\n");
           }
           if(count==noOfDomains-1 )
           {
               //If valid and invalid domains count are less than 10, then increase iterations by 5
               if(validCount<10 || invalidCount<10)
                   noOfDomains=noOfDomains+5;
           }
       }

   }
   //This method checks if the domainNAme matches the regex
   static boolean isValidDomain(String domainName)
   {
       //Atleast one digit, atleast one alphabet, length should be atleast 14 and max of 25

       String regex = "^.*[a-zA-Z0-9]"+"(?=\\S+$).{14,25}$";

       Pattern p = Pattern.compile(regex);

       Matcher m = p.matcher(regex);

       //check if regex matches, hyphen is present atleast once and first character is an alphabet

       if(m.matches() && domainName.contains("-") && String.valueOf(domainName.charAt(0)).matches("^[a-zA-Z]"))  
           return true;

       return false;
   }


}

Code Screenshot:

Output:

**************Please do upvote to appreciate our time. Thank you!******************

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments,...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to represent a headphone set. The class contains:  Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.  A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.  A private...
Need this done using PHP code and not javascript Create a PHP form with a textarea...
Need this done using PHP code and not javascript Create a PHP form with a textarea field input and a submit button. The textarea field should be able to accept up to 250 characters. When the user clicks the Submit button, read the text in the textarea and display the following results on a web age. At the bottom of the page include a link back to the form. Number of characters: Number of words: (hint: explode the string into...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database,...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database, exercise use of arrays of objects, external classes, processing files and user interaction. For this project, you will design and implement a program that analyzes baby name popularities in data provided by the Social Security Administration. Every 10 years, the data gives the 1,000 most popular boy and girl names for kids born in the United States. The data can be boiled down to...
What would the pseudocode be for this? The code for this has already been answered. I...
What would the pseudocode be for this? The code for this has already been answered. I need the pseudocode. Credit card numbers typically consist of 13, 15, or 16 digits. For example, 4690 3582 1375 4657 is a hypothetical credit card number. The first digit designates the system. In (3.1.1), the first digit, 4, shows that the card would be a Visa card. The following digits specify other information such as the account number and bank number. (The precise meaning...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
***Programming language is Java. After looking at this scenario please look over the requirements at the...
***Programming language is Java. After looking at this scenario please look over the requirements at the bottom (in bold) THIS IS ALL THAT WAS PROVIDED. PLEASE SPECIFY ANY QUESTIONS IF THIS IS NOT CLEAR (don't just say more info, be specific)*** GMU in partnership with a local sports camp is offering a swimming camp for ages 10-18. GMU plans to make it a regular event, possibly once a quarter. You have been tasked to create an object-oriented solution to register,...
Write a Python 3 program called “parse.py” using the template for a Python program that we...
Write a Python 3 program called “parse.py” using the template for a Python program that we covered in this module. Note: Use this mod7.txt input file. Name your output file “output.txt”. Build your program using a main function and at least one other function. Give your input and output file names as command line arguments. Your program will read the input file, and will output the following information to the output file as well as printing it to the screen:...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...