vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   convert IP to 10 digit decimal number (https://vborg.vbsupport.ru/showthread.php?t=77850)

Aurous 03-10-2005 10:04 AM

convert IP to 10 digit decimal number
 
Hi guys I need help in converting IP in php.

for example, if we have this IP: 123.456.789.012

I would like to make it as 012.789.456.123

and then convert it to a 10 digit decimal number. This is for a hack I am working on and will be greatful if anyone can help.

Thanks

Aurous

Marco van Herwaarden 03-10-2005 10:12 AM

Why 10 digits, why not 12?

Aurous 03-10-2005 01:04 PM

Quote:

Originally Posted by MarcoH64
Why 10 digits, why not 12?

http://livinginternet.com/i/iw_dns_alias.htm

filburt1 03-10-2005 01:07 PM

<a href="http://us4.php.net/manual/en/function.ip2long.php" target="_blank">http://us4.php.net/manual/en/function.ip2long.php</a>

Aurous 03-10-2005 01:08 PM

Quote:

Originally Posted by filburt1

ya I understood the ip2long function. How about reversing the IP address before I use the function?

Marco van Herwaarden 03-10-2005 02:12 PM

How about:
PHP Code:

$reversedlong ip2long(implode(".",array_reverse(explode("."$ip)))); 


filburt1 03-10-2005 02:47 PM

That's what I was going to suggest as well.

Marco van Herwaarden 03-10-2005 02:49 PM

Yes i know you suggested it ;) but he had trouble reversing it.

Aurous 03-10-2005 03:02 PM

Quote:

Originally Posted by MarcoH64
Yes i know you suggested it ;) but he had trouble reversing it.

Actually the way I need to reverse is as follows:

If the IP is suppose: 123.456.78.90

It should reverse it to 90.78.456.123

They way you suggest would make it 321.654.87.09 (i think), which I dont want to do.

basically if the IP I need to get this -> 3092948441 when this is entered as IP -> 217.165.90.184

This is an example.

Marco van Herwaarden 03-10-2005 03:55 PM

Don't think too much ;)

It would already do that, i a review with the ip you now provided i found out that the sprintf is really neccesary to avoid negative numbers.

PHP Code:

<?php
$ip 
"217.165.90.184";
echo 
"<br />ip: $ip";
$reversed implode(".",array_reverse(explode("."$ip)));
echo 
"<br />reversed: $reversed";
$reversedlong sprintf("%u",ip2long(implode(".",array_reverse(explode("."$ip)))));
echo 
"<br />reversedlong: $reversedlong";
?>

Will produce:
Code:

ip: 217.165.90.184
reversed: 184.90.165.217
reversedlong: 3092948441


Paul M 03-10-2005 04:10 PM

Why do you need to reverse them ?

Aurous 03-10-2005 08:33 PM

Quote:

Originally Posted by MarcoH64
Don't think too much ;)

It would already do that, i a review with the ip you now provided i found out that the sprintf is really neccesary to avoid negative numbers.

PHP Code:

<?php
$ip 
"217.165.90.184";
echo 
"<br />ip: $ip";
$reversed implode(".",array_reverse(explode("."$ip)));
echo 
"<br />reversed: $reversed";
$reversedlong sprintf("%u",ip2long(implode(".",array_reverse(explode("."$ip)))));
echo 
"<br />reversedlong: $reversedlong";
?>

Will produce:
Code:

ip: 217.165.90.184
reversed: 184.90.165.217
reversedlong: 3092948441


Excellent MarcoH64 .. that did help! You are right about sprintf, thanks a million!

Paul M - Just have to, thats how things work sometimes :p

BTW, thanks for the help guys, i got what i wanted :) Really appreciate everyones help here, especially MarcoH64.


All times are GMT. The time now is 11:17 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01484 seconds
  • Memory Usage 1,749KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (3)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (12)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete