-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlisten.pl
46 lines (36 loc) · 988 Bytes
/
listen.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl -w
use IO::Socket;
use Net::hostent;
my $port = shift || 13131;
my $server = IO::Socket::INET->new(
Proto => 'tcp',
LocalPort => $port,
Listen => SOMAXCONN,
Reuse => 1 )
|| die "can't setup server";
print "[XMap listener $0 is now active on port $port]\n";
while( $client = $server->accept() )
{
$client->autoflush( 1 );
$hostinfo = gethostbyaddr( $client->peeraddr );
printf "[Connect from %s]\n\n", $hostinfo ? $hostinfo->name : $client->peerhost;
#ask the client for a command
print $client "[server]\$";
my $text = "";
while( <$client> )
{
$text .= $_;
while( $text =~ s|<message[^>]*>([^<]+)</message>|| )
{
my $msg = $1;
# fix xml ents
$msg =~ s|<|<|g;
$msg =~ s|>|>|g;
$msg =~ s|"|"|g;#"
$msg =~ s|'|'|g;#'
print $msg;
}
}
printf "\n[Disconnected: %s]\n\n", $hostinfo ? $hostinfo->name : $client->peerhost;
close $client;
}