I am trying to use SIPSAK to send OPTIONS to test various FreePBX machines if they are online or not. I have watched video, and read dozens of page on the command and tried vartious examples, but no matter what I try i am getting errors and no example I try seems to work. Supposedly I can put in an IP Address and i should get a 200 returned if the server is on and reachable.
Any suggestions here ?
I am logged into the FreePBX version 17 machine with debain 12. I just installed sipsak. it says version 0.9.8.1
I have tried :
sipsak -O -s sip:ip_address
Capital O - this gives the error : âerror : a SIP URI is needed at leastâ
sipsak -O -s sip:ip_address:5060
same error as above
sipsak -o -s sip:ip_address
small o - this gives the error : âerror : string is not a number : â-sâ
sipsak -O -s sip:full_URI.com
this gives the error : âerror : a SIP URI is needed at leastâ
I have tried to use the IP Address of teh machine i am sitting on, and tried to use the public IP Address of a clients site
Thanks. Ok, So I tried that and I am getting what appears to be a 401 Unauthorized. (it actually returns a LOT of info, but unauthorized is the first line - SIP/2.0 401 Unauthorized) In reading about this I do in fact have âAllow Anonymous Inbound SIP Callsâ and âAllow SIP Guestsâ set to NO. And it appears that is why I am getting a 401.
Since I am testing known machines and I have active accounts on and manage those machines, can I do a test with the full credentials ? Not a registration ? Should I get a single value back like 200 ? Or will it be part of the larger response and I need to parse it ?
Technically, a 401 is a valid response from the machine and that tells me it is up and running, but would also get me banned by Fail2Ban if I do it too often.
You donât need to parse the response. As I mentioned above, the return code will be 0 if it is successful and you examine the return code by using e.g. if statements in a shell scriptâŚ
if /usr/bin/sipsak -s sip:user@server -a password ; then
echo "All is well" ;
else
echo "Server did not give a successful response" ;
fi
You can test this out with echo $? after running a sipsak command. Youâll get 0 if it was successful (OPTIONS ping resulted in 200) and another number if it fails.
From the man pageâŚ
RETURN VALUES
The return value 0 means that a 200 was received. 1 means something else than 1xx or 2xx was received. 2 will be returned on local errors like non resolvable names or wrong options
combination. 3 will be returned on remote errors like socket errors (e.g. icmp error), redirects without a contact header or simply no answer (timeout).
Ok, well No matter what I try here i keep getting a 401. Even disabled the firewall completely to test it When I echo $? I get a 2. Username and Password are correct as its the same account I use on my cell phone with Groundwire.
If I keep the firewall on and keep testing it, Fail2Ban eventually bans our IP Address. So we can see the request is making it to the system
I get so frustrated with stuff like this where it seems so straight foreward and simple and should work, but I just cant get it to.
Sorry, I misled you a bit, and now I have figured out what to do after some more testing here.
The problem is that sipsak sends a From header of sip:sipsak@... and Asterisk takes this as the username. Since user sipsak doesnât exist, the auth always fails.
You can make it work by crafting your own OPTIONS packet that sipsak will send. Hereâs what I did.
Another note. If you want to use the same request file for several servers with different users you can use these replacement options with variables in your text file:
-g, --replace-string STRING
Activates the replacement of $replace$ within the request (usually read in from a file) with the STRING. Alternatively you can also specify a list of attributes and values. This list
has to start and end with a non alpha-numeric character. The same character has to be used also as separator between the attribute and the value and between new further attribute value
pairs. The string "$attribute$" will be replaced with the value string in the message.
-G, --replace
Activates the automatic replacement of the following variables in the request (usually read in from a file): $dsthost$ will be replaced with the host or domainname which is given by the
-s parameter. $srchost$ will be replaced by the hostname of the local machine. $port$ will be replaced by the local listening port of sipsak. $user$ will be replaced by the username
which is given by the -s parameter.