2 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
#!/usr/bin/perl
use IO::Socket;
use Thread;
# Wichtige Variablen festsetzen
my $HOST = shift || "localhost";
my $PORT = "30381";
my $LOG = "server_logfile.txt";
my $VERSION = "0.1";
my $server = &Create_Server_Socket();
print "Easyspider Server Version $VERSION bind to $PORT successful: Socket created!\n";
while ($client = $server->accept()) {
$client_ip = getpeername($client);
($port, $ipaddr) = unpack_sockaddr_in($client_ip);
$client_ip = inet_ntoa($ipaddr);
\&logmsg($LOG,"[$client_ip] Connection attempt!");
if (my $pid = fork) {
close $client or die "Client socket close failed: $!";
} elsif (defined $pid) {
#$client->autoflush(1);
&handle_connection($client,$client_ip);
} else {
die "fork error: $!";
}
}
##### Wichtige Soubroutinen
sub handle_connection(){
my $client = @_[0];
my $client_ip = @_[1];
# handle handshake procedure here
$msg = <$client>;
if( $msg =~ /c_type=syn\(1\)/ ){
print "[" . localtime() . "] [$client_ip] Connection Setup Procedure SYN Paket recieved!\n";
&send_ack();
}
close $client;
}
sub send_ack(){
print $client "c_type=ack(1)\015\12";
return 1;
}
sub Create_Server_Socket(){
my $socket = new IO::Socket::INET(
LocalHost => $HOST,
LocalPort => $PORT,
Proto => 'tcp',
Listen => 2,
Reuse => 1,
Type => SOCK_STREAM,
) or die "Could not create Socket: $!\n" unless defined($socket);
\&logmsg($LOG,"Easyspider Server Version $VERSION bind to $PORT successful: Socket created!");
print "Easyspider Server Version $VERSION bind to $PORT successful: Socket created!";
return($socket);
}# sub Create_Server_Socket(){}
##### Zusätzliche Soubroutinen
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
#!/usr/bin/perl
use IO::Socket;
# Wichtige Variablen festsetzen
my $HOST = shift || "localhost";
my $PORT = "30381";
my $TIMEOUT = "333";
my $socket = new IO::Socket::INET(
PeerAddr => $HOST,
PeerPort => $PORT,
Proto => 'tcp',
# Timeout => $TIMEOUT,
) or die "can't connect to $HOST\n";
# Signalhandler setzen
$SIG{'CHLD'} = sub { wait(); }; # Zombies verhindern
$SIG{'TERM'} = $SIG{'INT'} = sub { close($socket) };
&handle_connection();
##########################################################
sub handle_connection(){
#handle handshake procedure
&send_syn;
$msg = <$socket>;
if( $msg =~ /c_type=ack\(1\)/ ){
print "[" . localtime() . "] [$HOST] Connection Setup Procedure ACK Paket recieved!\n";
print "now go one";
close($socket);
}
} #sub handle_connection(){}
#####################################################################################
sub send_syn(){
print $socket "c_type=syn(1)\015\12";
return 1;
}
2 Einträge, 1 Seite |