我使用Asterisk 1.8和Mysql版本5.1.69(操作系统:CentOS版本6.4,在虚拟机Oracle VM Virtual Box中配置)。从Win 7 32bit,我尝试使用此代码获取有关sip peer的信息:
import java.util.ArrayList;
import java.util.List;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.action.CommandAction;
import org.asteriskjava.manager.response.CommandResponse;
public class Manager
{
private ManagerConnection c;
public Manager() throws Exception
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"172.16.213.91", "asterisk", "asterisk");
c = factory.createManagerConnection();
}
public void run() throws Exception
{
c.login();
CommandAction action;
CommandResponse response;
List<String> list = new ArrayList<String>();
action = new CommandAction();
//action.setCommand("core show help");
action.setCommand(" sip show peers");
response = (CommandResponse) c.sendAction(action);
list = response.getResult();
System.out.println(list.size());
int i = 0;
while ( i <list.size())
{
System.out.println(list.get(i));
i++;
}
c.logoff();
}
public static void main(String[] args) throws Exception
{
new Manager().run();
}
}
我在控制台中输出了这个输出:
18 avr. 2014 11:01:07 org.asteriskjava.manager.internal.ManagerConnectionImpl connect
INFO: Connecting to 172.16.213.91:5038
18 avr. 2014 11:01:07 org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
INFO: Connected via Asterisk Call Manager/1.1
18 avr. 2014 11:01:07 org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
ATTENTION: Unsupported protocol version 'Asterisk Call Manager/1.1'. Use at your own risk.
18 avr. 2014 11:01:07 org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Successfully logged in
18 avr. 2014 11:01:07 org.asteriskjava.manager.internal.EventBuilderImpl buildEvent
INFO: No event class registered for event type 'fullybooted', attributes: {status=Fully Booted, event=FullyBooted, privilege=system,all}
18 avr. 2014 11:01:09 org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Determined Asterisk version: Asterisk 1.0
18 avr. 2014 11:01:09 org.asteriskjava.manager.internal.ManagerConnectionImpl disconnect
INFO: Closing socket.
2
Name/username Host Dyn Forcerport ACL Port Status Realtime
0 sip peers [Monitored: 0 online, 0 offline Unmonitored: 0 online, 0 offline]
甚至,我用sip用户连接到Asterisk。我得到了相同的结果。
我的数据库中有5个用户。
您能否帮助我获取有关sip同伴状态的信息(已连接或未连接,ip地址...)。我在我的项目中使用了asterisk-java-0.3.jar。
答案 0 :(得分:1)
您的代码适合我。我正在使用Asterisk 1.8 Cert和0.3 jar。
INFO: Determined Asterisk version: Asterisk 1.0
6
Name/username Host Dyn Forcerport ACL Port Status
1000 (Unspecified) D N 0 Unmonitored
1001 (Unspecified) D N 0 Unmonitored
1002 (Unspecified) D N 0 Unmonitored
1003 (Unspecified) D N 0 Unmonitored
我会查看manager.conf我的看起来像:
[manager]
secret=pa55w0rd
permit=0.0.0.0/255.255.255.255
read=all
write=all
直接使用telnet排除Java api连接到AMI。示例here
登录后。要发送cli命令,请使用
Action: Command
command: sip show peers
并按两次介绍。还尝试从安装Asterisk的机器本地连接到AMI。
<强>更新强> 我的manager.conf
[general]
enabled = yes
webenabled = yes
port = 5038
bindaddr = 0.0.0.0
[asterisk]
secret = asterisk
permit = 0.0.0.0/0.0.0.0
read=all
write=all
祝你好运!
答案 1 :(得分:1)
我尝试使用telnet这个命令
action: sippeers
actionid: 4
我收到了这个回复:
Response: Success
ActionID: 4
EventList: start
Message: Peer status list will follow
Event: PeerlistComplete
EventList: Complete
ListItems: 0
ActionID: 4
就像你可以看到的那样,我得到了无所事事。