hi

this code's working fine for localhost, and i got no timestamp reply when i tried this code to another host, would you try this code in your LAN ?

##Update-1##
Working fine for localhost ?
of course, we still can get timestamp reply even if the checksum value is incorrect (but just remember it's only for Localhost!)
##EndOfUpdate-1##

use strict; use Socket; use constant ICMP_TS => 13; use constant ICMP_STRUCT => "C2 n3 N3 A"; # Structure of a minimal ICM +P packet use constant SUBCODE => 0; use constant ICMP_FLAGS => 0; # No special flags for send or recv use constant ICMP_PORT => 0; # No port with ICMP use constant IOT => 0; #ICMP originate timestamp use constant IRT => 0; #ICMP receive timestamp use constant ITT => 0; #ICMP transmit timestamp ping_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_TS,SUBCODE,$checksum,$pid,$seq,IOT, +IRT,ITT,$data); $checksum =checksum($msg); $msg = pack(ICMP_STRUCT . 0,ICMP_TS,SUBCODE,$checksum,$pid,$seq,IOT, +IRT,ITT,$data); $len_msg = length($msg); $saddr = sockaddr_in(ICMP_PORT, $ip); socket(SOCK,PF_INET,SOCK_RAW,1) or die "error: $! \n"; send(SOCK,$msg,ICMP_FLAGS,$saddr) or die "error: $!\n"; } 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 }

thanks


In reply to icmp timestamp request, not sure 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.