Sponsored Content
Special Forums IP Networking converting ip addresses to binary Post 302242489 by jetole on Thursday 2nd of October 2008 04:08:05 AM
Old 10-02-2008
Ok, well since no one bothered to answer your first question (although credit to the person who assumed it was a programming question), lemme give it a shot. An IP address in decimal is a representation of a 32 digit binary number, you can convert each section to binary and keeping it in order you will have the binary IP address, for example, let's convert 127.0.0.1, now remembering each octet is 8 digits in a 32 digit binary number, we convert 127 which is 11111111, 0 which is 00000000, and 1 which is 00000001, so 127.0.0.1 is 11111111 0000000 00000000 00000001 where each block represents an IP octet however an IP address 127.0.0.1 is the whole number of 11111111000000000000000000000001.

Just remember, you want to convert each number into an 8 digit binary number, however, the first octet can be shorter if the octet produces a binary number with leading 0's for example, 10.0.0.1 would produce 00001010000000000000000000000001 however that can simply be written as 101000000000000000000000001 since the leading 0's server no purpose and is identical to comparing decimal $500 and $000,500, or 10.5 and 10.50000, they are all the same numbers but leading 0's or trailing decimal 0's just don't change the output.

Now if you want your subnet on linux:
CIDR notation: ip addr ls | grep 'inet ' | cut -d' ' -f6
dotted octet notation: ifconfig | tr ' ' '\n' | grep Mask | cut -d':' -f2
 

10 More Discussions You Might Find Interesting

1. IP Networking

ip addresses

this might sound corny but i need help finding out about finding a persons ip address can u halp? and another question what the hell does ping mean??? thank u. (2 Replies)
Discussion started by: dragonslayer100
2 Replies

2. Shell Programming and Scripting

unix script for converting a decimal to binary

Could anybody please help me in writing a script in unix for converting a decimal number to binary number. (3 Replies)
Discussion started by: softy
3 Replies

3. UNIX for Advanced & Expert Users

Converting ASCII to Binary mode

Dear All, Business Users are transfering ( FTP ) a CSV file into the IBM AIX box with transfer mode as ASCII. But I want to convert the CSV file from ASCII mode into binary mode, as my script expects file in binary mode. Is it possible to do through Unix commands? Thanks in Advance, RK (1 Reply)
Discussion started by: srajeshmca
1 Replies

4. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies

5. Linux

Converting source rpm to binary rpm

Hi, I need to install an rpm file,but I only have '.src.rpm' version of it. I want to convert it to a binary rpm. so I tried this rpm --rebuild somethin.src.rpm But I am gettin '--rebuild:Invalid option' as output Is there another way to rebuild source rpm.? Thanks in... (2 Replies)
Discussion started by: eamani_sun
2 Replies

6. Programming

Converting HexDecimal To Binary - 'C' programming

guys, Can somebody help me with a Unix 'C' program, to convert the Hexa decimal value to binary value. Thank you Cheers :) S (3 Replies)
Discussion started by: sudharma
3 Replies

7. UNIX for Dummies Questions & Answers

Converting binary file to readable format in Ksh

In Unix/Ksh, when I try to look inside a file it says that the file may be a binary file and if I want to see it anyway. When i say 'yes', it shows me the content filled with unreadable symbols (looks like binary). Is there a command that I can run from the Unix prompt to convert/translate that... (3 Replies)
Discussion started by: arthurs
3 Replies

8. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

9. Shell Programming and Scripting

Converting a binary file to ascii and vice versa?

Hi All, I have a binary file which is being exported from a Database, and i need to convert that to ASCII format. How can i achieve that? And this solution should work for any file which is given to us; means they will give different files from different tables. Thanks in advance. (8 Replies)
Discussion started by: baranisachin
8 Replies

10. UNIX for Dummies Questions & Answers

Converting binary file to text file

Hi, Im wondering how I can convert a binary file to a text file? I have ran the following command to output which type of binary file coding it is od -t x1 -c eHat.data0 | head -20 and that gives me the following output; 0000000 5c 00 00 00 cd 06 f2 41 00 00 00 c6 00 00 00 c6 \ \0 \0 \0... (3 Replies)
Discussion started by: dp0b
3 Replies
IPSEC_SAMEADDR(3)					     Library Functions Manual						 IPSEC_SAMEADDR(3)

NAME
ipsec_sameaddr, ipsec_addrcmp, ipsec_samesubnet, ipsec_addrinsubnet, ipsec_subnetinsubnet, ipsec_subnetishost, ipsec_samesaid, ipsec_sameaddrtype, ipsec_samesubnettype - do comparisons for addresses, subnets, SA IDs and address families SYNOPSIS
#include <freeswan.h> int sameaddr(const ip_address *a, const ip_address *b); int addrcmp(const ip_address *a, const ip_address *b); int samesubnet(const ip_subnet *a, const ip_subnet *b); int addrinsubnet(const ip_address *a, const ip_subnet *s); int subnetinsubnet(const ip_subnet *a, const ip_subnet *b); int subnetishost(const ip_subnet *s); int samesaid(const ip_said *a, const ip_said *b); int sameaddrtype(const ip_address *a, const ip_address *b); int samesubnettype(const ip_subnet *a, const ip_subnet *b); DESCRIPTION
These functions do various comparisons and tests on the ip_address type and ip_subnet types. Sameaddr returns non-zero if addresses a and b are identical, and 0 otherwise. Addresses of different families are never identical. Addrcmp returns -1, 0, or 1 respectively if address a is less than, equal to, or greater than b. If they are not of the same address fam- ily, they are never equal; the ordering reported in this case is arbitrary (and probably not useful) but consistent. Samesubnet returns non-zero if subnets a and b are identical, and 0 otherwise. Subnets of different address families are never identical. Addrinsubnet returns non-zero if address a is within subnet s and 0 otherwise. An address is never within a subnet of a different address family. Subnetinsubnet returns non-zero if subnet a is a subset of subnet b and 0 otherwise. A subnet is deemed to be a subset of itself. A sub- net is never a subset of another subnet if their address families differ. Subnetishost returns non-zero if subnet s is in fact only a single host, and 0 otherwise. Samesaid returns non-zero if SA IDs a and b are identical, and 0 otherwise. Sameaddrtype returns non-zero if addresses a and b are of the same address family, and 0 otherwise. Samesubnettype returns non-zero if subnets a and b are of the same address family, and 0 otherwise. SEE ALSO
inet(3), ipsec_initaddr(3) HISTORY
Written for the FreeS/WAN project by Henry Spencer. 28 Nov 2000 IPSEC_SAMEADDR(3)
All times are GMT -4. The time now is 11:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy