thanks before,

actually this script's working fine for localhost, and i got a reports from some ppl that this script is working fine too in their LAN, just to make sure i remade this script (well..actually it's only copied and pasted from ping.pm)..

##Update-2##
Well, i just found out that if we send single icmp packet to LOCALHOST we dont need a 'right value' for checksum, i mean we can put any numbers into $checksum, so for Localhost we dont need sub checksum
##EndOfUpdate-2##

use strict; use Socket; ping_icmp(); use constant ICMP_ECHOREPLY => 0; # ICMP packet types use constant ICMP_ECHO => 8; use constant ICMP_STRUCT => "C2 n3 A"; # Structure of a minimal ICMP p +acket use constant SUBCODE => 0; # No ICMP subcodefor ECHO and ECHOREPLY use constant ICMP_FLAGS => 0; # No special flags for send or recv use constant ICMP_PORT => 0; # No port with ICMP sub ping_icmp { my ($ip) = inet_aton('192.168.0.2'); my ($saddr, $checksum, $msg, $len_msg); my $seq = 1; my $pid = $$ & 0xffff; $checksum = 0; # No checksum for starters my $data= ""; $msg = pack(ICMP_STRUCT . 0,ICMP_ECHO,SUBCODE,$checksum,$pid,$seq,$d +ata); $checksum =checksum($msg); $msg = pack(ICMP_STRUCT . 0,ICMP_ECHO,SUBCODE,$checksum,$pid,$seq,$d +ata); $len_msg = length($msg); $saddr = sockaddr_in(ICMP_PORT, $ip); socket(SOCK,PF_INET,SOCK_RAW,getprotobyname('icmp')); send(SOCK,$msg,ICMP_FLAGS,$saddr); } sub checksum{ my ($msg) = @_; my ($len_msg,$num_short,$short,$chk); $len_msg = length($msg); $num_short = int($len_msg / 2); $chk = 0; foreach $short (unpack("n$num_short", $msg)) { $chk += $short; } $chk += (unpack("C", substr($msg, $len_msg - 1, 1)) << 8) if $len_ms +g % 2; $chk = ($chk >> 16) + ($chk & 0xffff); # Foldhigh into low return(~(($chk >> 16) + $chk) & 0xffff); # Again and complement }
would you mind to test this script in your LAN and send me a report?
nb : maybe u can add this lil code (thanks to satuspam aka edwin pramono from id-perl yahoogroup)..

***UPDATE***
Because i still got weird result from this code (below), i'll strike this code

my $buff; defined(recv(SOCK,$buff,256,0)) or die "error: $! \n"; print "received: ", length($buff), " bytes\n"; my($type,$subcode,$cksum,$recv_pid,$recv_seq)=unpack(ICMP_STRUCT,sub +str($buff,20)); if($type == ICMP_ECHOREPLY) { if($recv_pid != $pid) { print "icmp reply ignored (different pid) \n"; } elsif($recv_seq != $seq) { print "icmp reply ignored (different seq) \n"; } else {print "got icmp reply \n"}; } else { print "not an icmp reply\n"; } }


thank you

In reply to Re^4: icmp code, w/o Net::Ping and problem by doctor_moron
in thread icmp code, w/o Net::Ping and problem by doctor_moron

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.