Results 1 to 3 of 3
-
07-07-2012, 12:57 #1
-= TeamSpeak User =-
- Join Date
- Jul 2012
- Posts
- 1
Strip nicknames from clientlist response using Perl script
Hi guys
I wonder if anyone could help point me in the right direction here. I'm trying to setup a script to monitior a 3rd party teamspeak 3 server, and return the list of currently logged in users, by parsing the result of the clientlist command.
What I've got so far seems to be close, but think the regexp needs adjusting slightly, as its only returning the first user (sorry I'm not great with regular expressions!). Here is what I have so far that was trying to print a comma seperated list of users:
Has anyone does this already, or have any advice on the above?Code:#!/usr/bin/perl use IO::Socket; my $sock = new IO::Socket::INET (PeerAddr => 'xxx.xxx.xxx.xxx',PeerPort => 'xxxx',Proto => 'tcp'); die "Could not create socket: $!\n" unless $sock; # Login details for TS print $sock "login ****** ******\n"; # Virtual TS server ID print $sock "use sid=xx\n"; # Command to run print $sock "clientlist\n"; # Array to hold users online @users = (); # Do text parsing to check for users value while (<$sock>) { /error id=(\d+)/ and $1 !~ /^0$/ and print "error\n" and close $sock; /client_nickname=(\S+)/ and push(@users,"$1") and close $sock; } # Output users online print join(",",@users);
Thanks!
-
20-07-2012, 00:57 #2
-= TeamSpeak Addict =-
- Join Date
- Jun 2012
- Location
- Earth
- Posts
- 137
Try this maybe...
Tested Code:
Code:#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $query_address = "192.168.0.2"; my $query_port = 10011; my $login = "serveradmin"; my $pass = "*********"; my $sid = 1; my $sock = IO::Socket::INET->new( PeerAddr => $query_address, PeerPort => $query_port, Proto => 'TCP', Autoflush => 1, Blocking => 1, ) or die "Server Failed to Start : $@"; # Login to TS3 print $sock "login $login $pass\n"; print $sock "use sid=$sid\n"; # Ask for clientlist print $sock "clientlist\n"; # Wait for server/query to receive above socket data sleep(1); # Receive clientlist from socket response my ($data); $sock->recv($data,4096); # Not sure if your program continues but just in case... close($sock); if ( $data =~ /error id=([^0?]\d+)/ ) { # Error Handler...? print "Error Fetching Clientlist\n"; } else { # Array to hold users online my @users = $data =~ /client_nickname=(.+?) /gi; # Output Array With Users Online print join(', ',@users)."\n"; }Last edited by Scor9ioN; 21-07-2012 at 00:43. Reason: Updated Code.
-
20-07-2012, 19:03 #3
-= TeamSpeak Addict =-
- Join Date
- Jun 2012
- Location
- Earth
- Posts
- 137
OR if you need that while(<$sock>) loop instead (I hate adding sleep in that last code, unless it was forked off the parent)..
I've tested this also..
Code:#!/usr/bin/perl use strict; use warnings; use IO::Socket; my $sock = IO::Socket::INET->new( PeerAddr => "voice.server.com", PeerPort => 10011, Proto => 'TCP', Autoflush => 1, ) or die "Socket Failed To Start : $@"; print $sock "login serveradmin *******\n"; print $sock "use sid=1\n"; print $sock "clientlist\n"; # Declare undefined array. my @users = (); while(defined(my $data = <$sock>)) { if ($data =~ /error id=([^0?]\d+)/) { print "Error Fetching Clientlist\n"; last; } elsif ($data =~ /client_nickname/) { # replace global array with this. @users = $data =~ /client_nickname=(.+?) client/gi; last; } } # Process defined array. if (@users) { # Some nicknames have \s for a whitespace. replace with our own whitespace. s/\\s/ /gi for @users; # Take a look at what we did. print join(', ',@users)."\n"; } close($sock); exit(0);Last edited by Scor9ioN; 21-07-2012 at 00:44. Reason: Updated Code.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Perl Webpost Script
By Hitman69 in forum [TeamSpeak 2] Addons & ScriptsReplies: 12Last Post: 24-11-2006, 13:13 -
Tx perl auto idlekick script setup question.
By lakosked in forum [TeamSpeak 2] Addons & ScriptsReplies: 2Last Post: 20-02-2006, 18:19 -
Webpage status perl script
By Hitman69 in forum [TeamSpeak 2] Addons & ScriptsReplies: 4Last Post: 21-07-2004, 23:32 -
Teamspeak 2 stats script for Perl (simple)
By Makull in forum [TeamSpeak 2] Server SupportReplies: 1Last Post: 27-08-2002, 15:21


Reply With Quote
