Results 1 to 5 of 5

Thread: perl: Dec to Ip address

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    perl: Dec to Ip address

    how would I do this:


    Convert this number

    3516293025


    From dec to a IP address ??

    thanks!

  2. #2
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    huh? Ip addy's are in decimal, there sint a conversion.

    You've got Hex, Binary, and Decimal.. there isnt an "IP". Its probably just encrypted or something

    or maybe i just dont understand your question

    -morrowasted

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Sorry.. Ill be clearer.

    an ip address is a 4x 4byte dec numbers.

    10.10.5.3

    he took the number and went to bin..

    1010101001010011 (10.10.5.3)

    then got a 16byte integer

    I need to get it back to the 10.10.5.3 =)

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Use shift (>>) and bitwise and (&) to split it up into the four bytes, then concatenate them with dots.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You're mistaken about the IP btw. An IP in the xxx.xxx.xxx.xxx representation is 4 1-byte integers, and the number you have is a single 4-byte integer.

    You can use modulo and division to get the original number, but bit shifting is faster.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width