I have following requirement.
1)There are three entities in the program. node A (Linux box),B(Windows Server) and C(Any node). Node C is unreachable from Node A directly. Node B is a Windows server, where a perl script has to manage the transfer of ping request from a perl script in node A node C and then return the message (pass/fail) to node A.
2) I am ready with a perl Server script in Windows server, which accepts ping request from client script and pings node C successfully. Using IO::Socket module.
Requirement:
there can be N number of client like node A which will be pinging node C through script running in Node B. Script in Node B should accept the IP address from Client A, Ping the node specified and send the result to that client. For that I can't figure out how in Node B can I determine the port and Ip address of node running client A kind of application. So that I can send the result to client A and client A displays the result and dies
MyServer.pl
#!/usr/bin/perl use IO::Socket; use Net::Ping; $sock = new IO::Socket::INET (LocalHost => 'xxx.xxx.xxx.xxx', LocalPor +t => 9321, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Socket could not be created. Reason: $!" unless $sock; $reach = Net::Ping->new($ > ? "tcp": "icmp"); (defined $reach) or die "Couldn't create Net::Ping object: $!\n"; while ($new_sock = $sock->accept()) { while (defined ($buf = <$new_sock>)) { print $buf; $host = (split(/:/,$buf))1; print "$host"; if($reach->ping("$host")) { print "host is reachable"; } else { print "host is unreachable"; } } }#end of 1st while loop close ($sock);

MyClient.pl
#!/usr/bin/perl use IO::Socket; use Net::Ping; $destination = '198.148.129.182'; $sock = new IO::Socket::INET (PeerAddr => '172.30.166.234', PeerPort = +> 9321, Proto => 'tcp', ); die "Socket could not be created. Reason: $!\n" unless $sock; print $sock "ping:$destination \n"; close ($sock);
Cheers,
Rock

Edited by planetscape - added code tags

( keep:0 edit:23 reap:0 )


In reply to Ping from remote host which is a Windows server by rockmountain

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.