ArgeliusLabs / FaviconLocator

Computes the hashes of a favicon file and provides the search syntax for Shodan, Censys and Zoomeye
36 stars 4 forks source link

Entering favicon name directly on command line #1

Open MikePeters86 opened 6 months ago

MikePeters86 commented 6 months ago

I'm a GitHub novice not yet familiar with pull requests. That is why I enter my 'issue' here.

It would be nice to have the ability to provide the favicon filename directly on the command line instead of being asked for it. Something like the code below would work (or rather: does work. I have already changed it on my own machine). Needs an import sys.

if len(sys.argv) < 2:
    # If no filename was provided as argument, ask for the name of the favicon file
    file_name = input("Please enter the name of the favicon file (including the extension): ")
else:
    # Get icon filename from command line
    file_name = sys.argv[1]
RoseSecurity commented 6 months ago

@MikePeters86 Awesome request! I opened a PR that addresses this issue as well. Python provides a module for parsing command line arguments while also having a built-in help menu. Here is a little of what the code looks like:

[!NOTE] I am working on a few features to directly download the favicon image from the URL provided so disregard that portion for now

def favicon_locator():
    parser = argparse.ArgumentParser(
        description='Generate favicon hash for search.')
    parser.add_argument('-f', '--file', help='The name of the favicon file')
    parser.add_argument(
        '-u', '--url', help='The url of the site to search for favicon (ex: https://www.kfc.com)')
    args = parser.parse_args()
    if args.url:
        webpage_url = args.url
        favicon_url = get_favicon_url(webpage_url)
        file_name = download_favicon(favicon_url)
        md5_hash = generate_md5_hash(file_name)
        mmh3_hash = compute_mmh3_hash(file_name)
        output(md5_hash, mmh3_hash)
    elif args.file:
        file_name = args.file
        md5_hash = generate_md5_hash(file_name)
        mmh3_hash = compute_mmh3_hash(file_name)
        output(md5_hash, mmh3_hash)
    else:
        parser.print_help()
        exit(1)

On the command line, it looks like:

$ python3 favicon_locator.py -f favicon.ico
RoseSecurity commented 6 months ago

@MikePeters86 For creating a PR on this repository, you can roughly follow these steps:

  1. Create a fork of this repository
  2. Clone the repository to your local workstation. For me, this looks like:
git clone git@github.com:RoseSecurity/FaviconLocator.git
  1. Create a new branch for your updates:
git checkout -b accept-file-via-cli
  1. Make any code additions and changes
  2. Add the files
git add <files>
  1. Commit changes
git commit -m 'Allow files to be accepted via the CLI'
  1. Push and open a PR
git push
# Note: this should show a URL where you can create the PR