InSe0F
Full Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору # bool chechSocketIfRunning($port) # Checks localhost for open port $port. sub chechSocketIfRunning { my ($port) = @_; local $SIG{__WARN__} = sub{}; # to avoid undef warning after send() local *SOCK; my $test = "This is the test string"; return socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) && connect(SOCK, pack_sockaddr_in($port, inet_aton("127.0.0.1"))) && send(SOCK, $test, 0) > length($test)-2; # or -3, or -4 etc. } |