-
Notifications
You must be signed in to change notification settings - Fork 89
/
ocs-socket
executable file
·40 lines (37 loc) · 1.27 KB
/
ocs-socket
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
#!/usr/bin/perl
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: Send s message to other machine via socket.
# Ref:http://www.perlfect.com/articles/sockets.shtml
use IO::Socket;
$usage="Usage: $0 [-h|--host HOSTNAME] [-p|--port PORT_NO] [-m|--message MSG]";
sub usage_details{
die "$usage\n".
"-h, --host HOST Assign the destination machine as HOST. You can assign FQDN or IP address. No default value\n".
"-p, --port NO Assign the port number NO. No default value\n".
"-m, --message MSG Specify the message you want to send as MSG. No default value\n".
";"
} # end of usage_details
die "$usage\n" if $#ARGV<0;
while ( $_ = shift ) {
if (/-p$|--port$/) {
$port = shift;
}elsif(/-h$|--host$/) {
$host = shift;
}elsif(/-m$|--message$/) {
$message = shift;
}elsif(/--help$/) {
usage_details();
}
}
die "$usage\n" if ! $host;
die "$usage\n" if ! $port;
die "$usage\n" if ! $message;
my $socket = new IO::Socket::INET (
PeerAddr => "$host",
PeerPort => "$port",
Proto => 'tcp',
);
die "Could not create socket to $host:$port!\n" unless $socket;
print $socket "$message\n";
close($socket);