I'm trying to make a simple port scanner bash script and I keep running into this error.
./tcpscan.sh: line 10: ((: counter=: syntax error: operand expected (error token is "=")
tcpscan.sh
#!/usr/bin/bash
host=$1
firstport=$2
lastport=$3
function portscan
{
for ((counter=$fristport; counter<=$lastport; counter ))
do
(echo >/dev/tcp/$host/$counter) > /dev/null 2>&1 && echo "$counter open"
done
}
portscan
CodePudding user response:
The error is caused because you are trying to set the value of counter to a non-existent value. Fix the transposed characters in your variable name.
CodePudding user response:
#!/usr/bin/bash
host=$1
firstport=$2
lastport=1$3
function portscan
{
for ((i = ${firstport} ; i <= ${lastport} ; i ))
do
echo "/dev/tcp/$host/$i" >> /dev/null 2>&1 && echo "$i open"
done
}
portscan