Get some information from Astersik

I want to get some information from Asterisk by by script.
How can I get below information from Asterisk?
1- Number of defined extension on system
2- Number of connected extension on system with own IP address
3- Number of defined Trunks on system
4- Number of Trunks in using mode

Thanks for any help or guidance

asterisk -rx “[command]” will throw some info to console
1- command: sip show peers / iax2 show peers
2- command: sip show peers / iax2 show peers with ip filed specified
3- command: sip show peers / iax2 show peers / zap show channels / pri show spans (depends on trunk technology)
4- command: show channels / show channels verbose
I think this should be enough to start.

Thanks a lot for your attention
1- Unfortunately some peers are in “UNKNOWN” status and its IP address is not specified!! What wrong is about these peers??
2- what time has user logged to system?
In fact I want to get information about user such IP,log in Time, status of user(logged or unlogged).

Thanks in advance

AFAIK, this means the peer isn’t registering.

Thanks for your attention
1- According to your told, all defined extensions on system must to be listed on output?but on output there are a few extension!!
2- Regarding to another question I still wait .

Thanks for your attention.

SIP account marked as UNKNOWN didn’t registered, so it’t IP addr is unknown.
To monitor status, add qualify=yes to each sip account.
Getting register time, if You have SIP account 111
try sip show peer 111 and see if You get any time value there.
Otherwise You have to search for it through asterisk logfile.
(there should be registers/lagged/unreachable events with full date, seconds included)