Important alert: (current site time 7/15/2013 9:34:26 PM EDT)
 

VB icon

IP to Long IP! Check it out!

Email
Submitted on: 3/22/2001 5:58:56 PM
By: Bruno Ribeiro 
Level: Beginner
User Rating: By 4 Users
Compatibility: 5.0 (all versions), 4.0 (all versions), 3.0 (all versions)
Views: 22097
(About the author)
 
     This is a simple code that will take a make a normal ip a long ip! Long ips are like this one: 3333866552 (type this in the url on your browser if u doubt it works) The code is fully commented so any one with one day of perl coding can understand it. The code also explains how the convertion is done. I hope you like the code, and if u do, plz vote high for it =). If u have any doubt on it, post a comment here, i'll be glad on helping you =). Cya.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: IP to Long IP! Check it out!
= Description:This is a simple code that will take a make a normal ip a long ip! Long ips are like this one: 3333866552 (type this in the url on your browser if u doubt it works) The code is fully commented so any one with one day of perl coding can understand it. The code also explains how the convertion is done. I hope you like the code, and if u do, plz vote high for it =). If u have any doubt on it, post a comment here, i'll be glad on helping you =). Cya.
= By: Bruno Ribeiro
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=174&lngWId=6=for details.=**************************************

#!/usr/bin/perl
#################
#Long ips are not very well known and are a nice 
#alternate to the normal ip
#ex: www.linux.org = 198.182.196.56 = 3333866552
#so if u type 3333866552 in your browser u will 
#be taken to linux.org.
#Long ips are usefull for other things too, 
#like on irc dcc chats
#(if u don't know how irc dcc chats work go learn it)
#LongIPS can also be used to bypass firewalls that 
#blocks certain ips.
#O well this code is really only to show 
#how to do long ips
#and i also commented every line so 
#even a complete begginer can
#understand this =)
#Bye
#Bruno Ribeiro
###################
print "Ip to LongIP by Bruno Ribeiro\n\nEnter the ip to be made long: ";
#gets the user entry for ip
$ip = <STDIN>;
#when reading from stdin it is a nice idea to chomp the var =) 
#comment the line below and run if u doubt me =)
#it will have the same longip as result
#but it will insert a line break when u print $ip =)
chomp $ip;
#this var only exists for u to understand better how to convert an ip to a long ip.
$n = 256;
#this takes the $ip entered and splits it into the . so 
#each part of it is stored in the array
@sip = split(/\./,$ip);
#this calculates the long ip
$fip = (@sip[0]*($n * $n * $n))+(@sip[1]*($n * $n))+(@sip[2] * $n) + (@sip[3]);
print "The long ip for $ip is: $fip";


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
3/22/2001 6:51:33 PMJeff

Very Handy! Simple yet Small thanks!
(If this comment was disrespectful, please report it.)

 
3/29/2001 10:03:51 AMOrhan

Nice and concise!
But the correct format of accessing array elements is
: $array[index]
Not
: @array[index]
If you had used strict, then this would have been pointed out.
(If this comment was disrespectful, please report it.)

 
3/29/2001 12:14:21 PMBruno Ribeiro

O well, it is known that on perl u have lots of ways of doing the same thing =). But thanks for the comment =)
(If this comment was disrespectful, please report it.)

 
3/31/2001 2:05:57 AMPaC

why go through all that.

chomp($_=);
$longip=$longip*256+$_ for split /\./;

Orhan and yes you can use @array[] to access an element.
@array[index] is an array slice.
I suggest you check out perldoc/man perldata
(If this comment was disrespectful, please report it.)

 
10/1/2002 8:18:52 AM

Long IP is more formally known as IPv6 as well.
(If this comment was disrespectful, please report it.)

 
2/27/2003 1:05:37 PMserpent

mine comes up with loads of errors

(If this comment was disrespectful, please report it.)

 
1/16/2005 11:50:25 PMDon Steele

long ip is NOT ipv6. ipv6 uses 6 hexidecimal sets for ip's and gives you alot more ip possibilities. aka the diffrence between x.x.x.x <-- current ipv4
and x.x.x.x.x.x
and it would look like 205.110.54.109 <-- ipv4 and
8F.38.B9.A7.01.22
Huge diffrence this simply is converting it to an octal number wich according to the rfc is required you can also use hex to represent an ip address......
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.