Connection from .NET to Asterisk server

Hello,

I have installed Asterisk using AsteriskNow image in VirtualBox. I open the FreePBX configuration web page and the server status for every service is OK (green). I want to connect to Asterisk server using Asterisk.NET library:

manager = new ManagerConnection(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
manager.Login();

Which username and password should I use?
I’ve tried “admin”/"admin"which I use for logging in at FreePBX web administration and with “admin”/“amp111”, none of which work. I have not modified anything after installing AsteriskNow in VirtualBox.

Does anyone has experience connecting from .NET to Asterisk server?

Regards,
Tamash

The one in manager.conf

This is what my manager.conf file looks like:

[general]
enabled=yes
port=5038
bindaddr=0.0.0.0
displayconnects=no ;only effects 1.6+

[admin]
secret="amp111"
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = ...
write = ...
 

I dont see any username or password here. Only secret = “amp111”. Can you please tell me what this mean?
Should I manually add a new user with password in the manager.conf and use those credentials to connect from .NET?

Regards,
Tamash

User=admin & password=amp111. You should start from reading the basic of Asterisk Manager Interface.

asteriskdocs.org/en/3rd_Edit … I_id265383

Most of this information is also in the sample configuration file.

I have tried both “admin”/“amp111” and “myUser”/“myPassword”(added to manager.conf). Both throw from the Asterisk.NET.Test sample the following error:

AuthenticationFailedException: Authentication failed ... at ManagerConnection.cs:line 1263

I am running the sample code from http://sourceforge.net/projects/asterisk-dotnet/. Did someone tried and succeded connecting from a .NET application to Asterisk server?

Regards,
Tamash

It appears that not the authentication is the problem, but the connection to the Asterisk is not established. I am using the following code to connect to Asterisk:

Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.35"), 5038);
clientSocket.Connect(serverEndPoint);

and I get the following error:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.0.35:5038

Can someone tell me what am I doing wrong or what is the solution to this?

Regards,
Tamash

Tried to access it from an unpermitted address.

Where should I modify so that I can connect from Windows?
I my manager.conf file I have “bindaddr = 0.0.0.0” under [general] which should permit all addresses to connect to it right?
(I have AsteriskNow installed in VirtualBox using bridged connection and I want to connect to it from a .NET application that runs on the Windows host using that code sample).
Can you please help me out to figure this out?

Regards,
Tamash

Go through manager.conf and eliminate the options that couldn’t affect which machines could connect. There is only one in the fragment you quoted that is left that should be left. Incidentally it is wrong, even for what it is trying to do, although, depending on the implementation, that might not matter.

The misconfiguration is not specific to Windows.

This is the full manager.conf file:

[general]
enabled=yes
port=5038
webenabled = yes
bindaddr=0.0.0.0
permit=all
displayconnects=no ;only effects 1.6+

[admin]
secret="amp111" 
permit=all
read=system,call,log,verbose,command,agent,user,config,command,dtmf,
reporting,cdr,dialplan,originate
write = system,call,log,verbose,command,agent,user,config,command,dtmf,
reporting,cdr,dialplan,originate

#include manager_additional.conf
#include manager_custom.conf

Is there anything wrong that prevents me from connecting from the Windows machine? I have tried all ports from 5030 to 5150 at 192.168.2.35 (the IP where I can configure from FreePBX on my Windows machine) and none work.
Can I publish (just for testing) the Asterisk server from the VirtualBox VM on a public IP? Maybe I can connect that way to Asterisk. Which steps should I take in order to have my Asterisk server open to public?

Regards,
Tamash

As far as I can tell, “all” is not a recognized value.

I have changed “all” to 0.0.0.0/0.0.0.0. This should permit connections form all addresses right? If not, how can I permit connections from all addresses?

Now you start looking to see if it is blocked at the Linux firewall.

Hi!
I’d have tried disabling iptables and selinux
Then try connecting to your asterisk server from your windows machine with telnet:
telnet asterisk_ip 5038
If success, then there is no network connected problems.

I am using

and I get:

Asterisk Call Manger/1.1

which I think is a good sign.

However, after about 5 seconds I get

and no interaction to the Asterisk server was made.

From .NET, by running the above code, connecting to the same IP/Port, I get the same error:

Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.35"), 5038);
clientSocket.Connect(serverEndPoint);

===>

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.0.35:5038

Any ideas ??

Regards,
Tamash

I have changed from

to

and I was able to connect to Asterisk.

Apparently I needed to connect using IP protocol type.

Regards,
Tamash

That’s a Windows issue, not an Asterisk one. Asterisk uses TCP for manager.

I see. Then why can’t I connect to it using TCP protocol type? Should I add

tcpenable=yes
tcpbindaddr=0.0.0.0

to manager.conf ?

Presumably because that .NET framework call’s parameters don’t mean what you think they mean. There is nothing Asterisk specific in that line of code.

However the examples in the Visual Studio documentation suggest your original was correct, and IP makes no sense with stream. IP is a lower level protocol which is intrinsically datagram.

You should note that very few people use AMI from Windows.