ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Correct me if I am wrong but this scripts seems a lot faster then the previous one. Could it be that I do not have this script written corrrectly or that Perl IO::Socket is just quicker and more efficient?
ok, here's a client socket snippet from my own code:
Code:
# Create socket
$socket_errmsg = "";
$cfg::send_socket = IO::Socket::INET->new( PeerAddr => $server,
PeerPort => $port,
Proto => "tcp"
)
or $socket_errmsg =
"Couldn't create socket to $server port $port: $@";
if( !$socket_errmsg )
{
# DEBUG
print "get_sending_socket() Success\n";
}
Here's the Perl Net::Telnet module desc+examples http://search.cpan.org/~jrogers/Net-.../Net/Telnet.pm
If you're going to write a prog to do what you want, do it all in Perl, it'll be more robust & faster.
Perl has loads of Networking/Socket modules. See also the Perl Cookbook for pre-written examples.
See also: http://perldoc.perl.org/
I have my boss on my bumper and I really need to get this done. Can you just explain to me why this command always produces a closed anwser, no matter what address I put in. The logic is wrong and I have been looking around like crazy and it is driving me crazy:
Well, for a start you've got the logic backwards; if it connects, it returns true, but you print closed (and vice versa).
Eg on my mchine ssh is running (port 22) but port 230 is reserved (see /etc/services).
Using your code, I get 'closed' for 22 and 'open' for 230 (opposite of reality).
<RANT>
I'm going to go out on a limb, and assume that this script is a security audit tool to find hosts which have insecure services running on your network (sounds like it anyway). If that's the case, you should point out to your management that not allowing you to use the correct tools (i.e. nmap) to do the audit reliably and quickly is a far greater security risk than having a single host with a single nmap binary installed (chmod 500, if they like).
This sort of thing is /exactly/ what nmap was designed to do - a single line in cron and a list of hostnames is all you'd require to scan for telnet hosts automatically. Instead, they've got you hacking up a script in a language you're not comfortable with, that's proving to be difficult to implement and debug. Unreliable audit tools are worse than no audit tools.
I saw crap like this from admin' management when I worked in software support - they'd rather have completely un-patched hosts than allow outbound connections to update servers through their firewalls/proxies - for security, of course. Their idiotic management annoyed me then, and your idiotic management annoys me now. You can tell them I said as much.
</RANT>
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.