Hi all
ls it possible t convert the interger to ip
Thank you
Hi all
ls it possible t convert the interger to ip
Thank you
Yes.
Simon
I search google but couldn't get any solution
Can you send me information?
Thank you
Simon Lockhart wrote:
ls it possible t convert the interger to ip
Yes.
If you are using 128-bit integers, which according to some will also
change some day, thus one should be using "struct addrinfo" and:
getaddrinfo()
getnameinfo()
as those are the girlfriends of programmers.
Note that one should effectively avoid inet_pton/inet_ntop as they still
require the programmer to know about address families, the get*info()
ones ignore all those details.
Also see Itojun's (RIP ) excellent document at:
http://www.kame.net/newsletter/19980604/
and of course Eva's document at:
Eva M. Castro Homepage
Greets,
Jeroen
kcc wrote:
I search google but couldn't get any solution
Can you send me information?
Sure!
Easiest way.
Take the integer, plug it into windows 'calc'.
Go to 'View: Scientific'.
Hit 'Hex'. That will show you the hex representation of the integer. Notice that it's either 7 or 8 characters long.
If it's 7, prepend it with a 0.
Break that into 4 groups of 2. Those are the hex values for the four dotted quads.
Make sure 'Hex' is still selected, and put in the first 2 characters, then hit 'binary'. That's your first part of the IP. Repeat for the other 3.
For example, you have 1089055123 for an integer.
In Hex thats 40E9A993.
40 Hex = 64
E9 Hex = 233
A9 Hex = 169
94 Hex = 147
So your IP is 64.233.169.147
Ken
$ ping 1089055123
PING 1089055123 (64.233.169.147): 56 data bytes
64 bytes from 64.233.169.147: icmp_seq=0 ttl=242 time=105.418 ms
64 bytes from 64.233.169.147: icmp_seq=1 ttl=242 time=105.891 ms
^C
--- 1089055123 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 105.418/105.655/105.891/0.236 ms
a message of 14 lines which said:
Easiest way.
$ ping 1089055123
PING 1089055123 (64.233.169.147): 56 data bytes
It relies on an undocumented feature (it is not in RFC 791, nor in
getaddrinfo() manual)
Huh, learn something new every day!
Well, at least my method shows the underlying theory behind how the
conversion works
Thanks!
Ken Matlock
Network Analyst
(303) 467-4671
matlockk@exempla.org
The harder way:
Decimal: 1089055123
Hex (dashes inserted at octals): 40-E9-A9-93
Decimal (of each octet): 64-233-169-147
IP Address: 64.233.169.147
Robert D. Scott Robert@ufl.edu
Senior Network Engineer 352-273-0113 Phone
CNS - Network Services 352-392-2061 CNS Receptionist
University of Florida 352-392-9440 FAX
Florida Lambda Rail 352-294-3571 FLR NOC
Gainesville, FL 32611 321-663-0421 Cell
Robert D. Scott wrote:
The harder way:
Decimal: 1089055123
Hex (dashes inserted at octals): 40-E9-A9-93
Decimal (of each octet): 64-233-169-147
IP Address: 64.233.169.147
The Python way
>>> import socket, struct
>>> socket.inet_ntoa(struct.pack('>l', 1089055123))
'64.233.169.147'
ls it possible t convert the interger to ip
#!/usr/local/bin/perl
# Perl script to convert between numeric and dotted quad IPs.
# give credit to Paul Gregg for this one
while (<STDIN>) {
chomp; $input = $_;
if (/\./) {
($a, $b, $c, $d) = split(/\./);
$decimal = $d + ($c * 256) + ($b * 256**2) + ($a * 256**3);
} else {
$decimal = $_;
$d = $_ % 256; $_ -= $d; $_ /= 256;
$c = $_ % 256; $_ -= $c; $_ /= 256;
$b = $_ % 256; $_ -= $b; $_ /= 256;
$a = $_;
}
if ( ($a>255) || ($b>255) || ($c>255) || ($d>255) ) {
print "$0: Invalid input: $input\n";
} else {
printf ("Address: %d.%d.%d.%d is %u (Hex:%02x%02x%02x%02x)\n",
$a,$b,$c,$d, $decimal,$a,$b,$c,$d);
}
}
For the curious,
have a look at the IASON tools
and try
c:~$ natnum 1089055123
host_look("64.233.169.147","1089055123","1089055123").
host_name("64.233.169.147","yo-in-f147.google.com").
natnum takes a hostname, an integer or an IPv4 address and
shows you the IPv4 address, the integer and the hostname.
If you do maintain your /etc/hosts it will tell you the aliases too.
Most of the stuff is unix only, but I guess you can compile
natnum even for windows.
Kind regards
Peter
Matlock, Kenneth L wrote:
Robert D. Scott wrote:
The harder way:
Decimal: 1089055123
Hex (dashes inserted at octals): 40-E9-A9-93
Decimal (of each octet): 64-233-169-147
IP Address: 64.233.169.147
The "this could take all day" way :
(in bc with scale=0 for integer portions only)
1089055123/(2^24)%(2^8)
64
1089055123/(2^16)%(2^8)
233
1089055123/(2^8)%(2^8)
169
1089055123/(2^0)%(2^8)
147
(Note: 2^0=1 & x/1=x so last line could reduce to 1089055123%(2^8).)
-Nicholas
shadow@gti.net
My two cents:
# ping 1089055123
PING 1089055123 (64.233.169.147) 56(84) bytes of data.
64 bytes from 64.233.169.147: icmp_seq=1 ttl=248 time=2.55 ms
64 bytes from 64.233.169.147: icmp_seq=2 ttl=248 time=2.00 ms
To do in reverse, you can use 'sipcalc':
# sipcalc 64.233.169.147
-[ipv4 : 64.233.169.147] - 0
[CIDR]
Host address - 64.233.169.147
Host address (decimal) - 1089055123
Host address (hex) - 40E9A993
Network address - 64.233.169.147
Network mask - 255.255.255.255
Network mask (bits) - 32
Network mask (hex) - FFFFFFFF
Broadcast address - 64.233.169.147
Cisco wildcard - 0.0.0.0
Addresses in network - 1
Network range - 64.233.169.147 - 64.233.169.147
-evt
Normally, I don't participate in this sort of thing, but I'm a sucker for a "there's more than one way to do it" challenge.
Shadow wrote:
Robert D. Scott wrote:
The harder way:
Decimal: 1089055123
Hex (dashes inserted at octals): 40-E9-A9-93
Decimal (of each octet): 64-233-169-147
IP Address: 64.233.169.147
The "this could take all day" way :(in bc with scale=0 for integer portions only)
1089055123/(2^24)%(2^8)
64
1089055123/(2^16)%(2^8)
233
1089055123/(2^8)%(2^8)
169
1089055123/(2^0)%(2^8)
147(Note: 2^0=1 & x/1=x so last line could reduce to 1089055123%(2^8).)
-Nicholas
shadow@gti.net
The "ugly, please adjust according to your endianness, etc" way:
int *dec;
unsigned char *oct1, *oct2, *oct3, *oct4;
main(int argc, char **argv) {
dec = malloc(sizeof(int));
*dec = 1089055123;
oct4 = dec;
oct3 = oct4 + sizeof(char);
oct2 = oct3 + sizeof(char);
oct1 = oct2 + sizeof(char);
printf("dec: %lu ip: %hu.%hu.%hu.%hu\n", *dec, *oct1, *oct2, *oct3, *oct4);
}
.-- My secret spy satellite informs me that at Wed, 27 Aug 2008, Colin Alston wrote:
The harder way:
Decimal: 1089055123
Hex (dashes inserted at octals): 40-E9-A9-93
Decimal (of each octet): 64-233-169-147
IP Address: 64.233.169.147The Python way
>>> import socket, struct
>>> socket.inet_ntoa(struct.pack('>l', 1089055123))
'64.233.169.147'
The Perl way:
sub ntoa
{
my $one = shift;
my $four = $one & 0xff;
$one >>= 8;
my $three = $one & 0xff;
$one >>= 8;
my $two = $one & 0xff;
$one >>= 8;
return "$one.$two.$three.$four";
}
#or in one line, like ipcalc does:
sub ntoa_in_one_line { join(".", unpack("CCCC", pack("N", $_[0]))); }
print ntoa(1089055123) . "\n";
print ntoa_in_one_line(1089055123) . "\n";
Cheers,
Andree
For completeness:
sub aton_in_one_line { unpack('N',pack('C4',split(/\./,$_[0]))); }
Thanks,
ep
- --
Brian Epstein <bepstein@ias.edu> +1 609-734-8179
Network and Security Officer Institute for Advanced Study
Key fingerprint = 128A 38F4 4CFA 5EDB 99CE 4734 6117 4C25 0371 C12A
In MySQL :
SELECT INET_NTOA(ip_in_decimal) AS ipa;
.. or the reverse :
Aww come on, C gets way more "fun" than that
#define _u8 unsigned char
#define _u32 unsigned long
int main(void) {
_u32 ipn = 1089055123;
_u8 ipa[3];
_u8 oct = 0;
for (oct=0; oct <4; oct++){
ipa[oct] = (char)(
(ipn & (0xFF000000 >> (8*oct))) >> (8*(3-oct))
);
}
printf("%d.%d.%d.%d\n", ipa[0], ipa[1], ipa[2], ipa[3]);
return 0;
}