0

When I enter netcat [ip address] [port] I am asked to enter a password, I actually know the password, it is a date.

However, I would like to create a script that enters the the netcat ip and port number and then goes through a list of dates. I have created a large list of dates that contain the correct password, but I am unsure how to create a script that does what I want. The password (a date) is in ddmmyyyy format. I would really appreciate some help!

Just to make it clear what I am trying to do...

1) Script automatically enters: netcat [ip address] [port]
2) Script automatically enters: 01012000
3) Script automatically enters: netcat [ip address] [port]
4) Script automatically enters: 02012000
..................
500) Script automatically enters: netcat [ip address] [port]
501) Script automatically enters: 10082001 (CORRECT PASSWORD) Script end

*The script does not need to end when the password is correct, it would be nice, but not necessary. I am trying to just implement the concept first.

1 Answer 1

1

You could use brace expansion to create consecutive dates and pipe the input to netcat:

#!/bin/bash
for date in 2021-01-{01..31}; do
    echo $date | netcat somehost ...
done

Or, a bit more complicated: for date in 2021-{01-{01..31},02-{01..02}}; do ....

Or, read from a file while read -r date; do ...; done < dates.txt.

You may need to check how to make netcat quit on time, especially if the remote doesn't close the connection with the commands you gave. There's a few versions of netcat, mine has e.g. this option:

-q seconds
after EOF on stdin, wait the specified number of seconds and then quit.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.