use Socket; print inet_ntoa(scalar(gethostbyname($name)));
lub odwrotnie (szczególnie przydatne jeśli serwer WWW nie ustawia zmiennej REMOTE_HOST):
use Socket;
print gethostbyaddr (inet_aton("149.156.96.9"), AF_INET );
lub wykorzystac Net::hostent lub Net::DNS::Resolver
use Regexp::Common 'net';
/^$RE{net}{IPv4}$/;
lub dzięki modułowi:
use Net::DNS; $res = new Net::DNS::Resolver;
$domena = "cos.com.pl";
if ($res->search($domena,NS)) { print "domena $domena juz zarejestowana\n"; }
else { print "domena $domena wolna\n"; }
plus: mailto:+486xxxxxxxx@text.plusgsm.pl orange: mailto:50xxxxxxx@sms.centertel.pl lub jako LWP-przegladarka era: LWP-przegladarka
Gotowe skrypty:
http://sms.jfiok.org/ http://romke.info/sms/ http://ceti.pl/~miki/komputery/sms.html http://www.in.lublin.pl/miasto.pl.txt
W CPANie jest też kilka gotowych modułów, jak np. Net::SMS::12Move, Net::SMS::Genie, czy WWW::SMS.
use Net::NNTP;
$nn=Net::NNTP->new("news.task.gda.pl"); # polaczenie z serwerem
$n = $nn->list(); # lista grup
$n=$nn->group("pl.rec.gry.komputerowe"); # zmiana grupy
$n=$nn->next(); # wyjecie artykulu
$head=$nn->head(); # jego naglowek $article=$nn->article(); # caly artykul $body=$nn->body(); # tylko tresc print @$body; # wyswietl tresc
use IO::Socket;
my $sock = new IO::Socket::INET(Proto => 'tcp',
LocalPort => 5000, Listen => 5) or die "Sock: $!";
while (my $acc = $sock->accept()) {
print $acc "Hej hej!\n"; # tu komunikacja
my $odp=<$acc>;
close $acc;
}
inny sposób:
# set up the socket SERVER, bind and listen ... use POSIX qw(:sys_wait_h);
sub REAPER {
1 until (-1 == waitpid(-1, WNOHANG));
$SIG{CHLD} = \&REAPER; # unless $] >= 5.002
}
$SIG{CHLD} = \&REAPER;
while ($hisaddr = accept(CLIENT, SERVER)) {
next if $pid = fork; # parent
die "fork: $!" unless defined $pid; # failure
# otherwise child
close(SERVER); # no use to child
# ... do something
exit; # child leaves
} continue {
close(CLIENT); # no use to parent
}
Alternatywą są moduły Net::Server oraz Net::Server::Fork.
package MyPackage; use Net::Server; @ISA = qw(Net::Server);
sub process_request {
open(IN,"/etc/motd");
while(<IN>){
chomp; print "$_\r\n";
}
close(IN);
}
MyPackage->run(port => 9999);