5 Einträge, 1 Seite |
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/local/bin/perl
use IO::Socket;
use IO::Select;
use Win32::API;
use win32;
#use strict;
#use warnings;
my $server = IO::Socket::INET->new(
LocalPort => 2005,
type =>SOCK_STREAM,
Reuse => 1,
Listen => 10
) or die "Server läuft nicht: $@\n";
my $select = IO::Select->new($server);
while(my @readable = $select->can_read)
{
foreach my $socket (@readable)
{
if($socket == $server)
{
my $client = $socket->accept;
print "New client connects\n";
$select->add($client);
$client->print("Welcome\n");
}
else
{
my $computername = $socket->getline;
if (defined $computername)
{
chomp $computername;
my $WindowAvailable ="";
$WindowAvailable = FindWindow("$computername");
print "$WindowAvailable\n";
if ($WindowAvailable == 0)
{
#$client->print ("Window ist nicht vorhanden\n");
my $programmpfad = $0;
$programmpfad =~ s/[^\\]*?$//;
system "start \"$computername\" cmd.exe";
$socket->print("reconnect\n");
$socket->print("port=12346\n");
#delete_socket($select, $socket);
}
else
{
$socket->print ("Window ist vorhanden\n");
$socket->print("process still running\n");
$socket->print("port=2005\n");
}
}
else
{
print "Client says: [$computername]\n";
}
}
}
}
sub FindWindow
{
my $WindowName = shift(@_);
chomp $WindowName;
print "$WindowName";
my $FindWindow = new Win32::API('user32', 'FindWindow', [P,P], N);# or die print "$!";
my $name = 'Telnet 127.0.0.1';
my $class = 0;
my $topHwnd = $FindWindow->Call($class, $WindowName);
print "$topHwnd\n";
return $topHwnd;
}
sub delete_socket
{
my ($sel, $sock) = @_;
$sel->remove($sock);
$sock->close;
}
5 Einträge, 1 Seite |