ip address octet increments


 
Thread Tools Search this Thread
Top Forums Programming ip address octet increments
# 8  
Old 03-23-2007
My bad too. I wrote a quickie to try to increment the 3rd octet but I had the wrong increment. So I let the program compute the increments. Here it is...
Code:
$ cat sock.c
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

main(){
        struct in_addr a;
        int i;
        int incr;
        incr=inet_addr("255.10.20.30") - inet_addr("254.10.20.30");

        printf("1st incr = %d \n", incr);
        incr=inet_addr("255.11.20.30") - inet_addr("255.10.20.30");
        printf("2nd incr = %d \n", incr);
        incr=inet_addr("255.10.21.30") - inet_addr("255.10.20.30");
        printf("3rd incr = %d \n", incr);
        incr=inet_addr("255.10.20.31") - inet_addr("255.10.20.30");
        printf("4th incr = %d \n", incr);

        a.s_addr=inet_addr("255.10.20.30");
        for(i=0;i<5;i++) {
                printf("%s\n", inet_ntoa((struct in_addr) a));
                a.s_addr += 65536;
        }
        exit(0);
}
$ ./sock
1st incr = 1
2nd incr = 256
3rd incr = 65536
4th incr = 16777216
255.10.20.30
255.10.21.30
255.10.22.30
255.10.23.30
255.10.24.30
$

# 9  
Old 03-26-2007
perderabo..thank you. will try to implement this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash subtract fourth octet of an IP by 1

Hello, Im looking to help out my team by automating a simple search list. The user will look for a peering ip /30. For example 192.168.1.2/30 and gets the result. Im trying to get the entered /30 and subtract the last octet by one. echo -n "Enter peering ip : "; read peeringip cat... (3 Replies)
Discussion started by: D'go
3 Replies

2. Programming

Celisus & fahrenheit table converter with fields + increments

no longer needed, please delete thread. (0 Replies)
Discussion started by: xtina
0 Replies

3. Shell Programming and Scripting

Awk: Help with how to remove 4rth octet :

Experts, In one example I have seen how to get output upto 3rd octet, when there is a ":" separated with the 4rth octet. However in this example how to remove 4rth octet and to keep upto 3rd octet with regular expressions and awk sub function: I have tried with :but not working: # awk '{... (3 Replies)
Discussion started by: rveri
3 Replies

4. Shell Programming and Scripting

awk Quick Help: printing upto 3rd octet .

Hi Experts, I am trying to print $2 & the IP_address upto 3rd octet only. But unable to do so, Trying # awk '{print $2, substr($4,1,9)}' file . but not correct File: HOST= cmiHOST06 :: 10.26.107.73:/data120 /nbu/cmiHOST06/athpx07/aa1 HOST= cmiHOST05 :: 10.26.12.76:/data120... (5 Replies)
Discussion started by: rveri
5 Replies

5. UNIX for Dummies Questions & Answers

What is an (application/octet-stream) file?

I'm trying to learn as much about GRUB as I can and it's stages are stored in these types of files. Any info or search terms is appreciated!:wall: (5 Replies)
Discussion started by: theKbStockpiler
5 Replies

6. Shell Programming and Scripting

Increments in a loop

Hi All, I am trying to implement a for loop in a .sh file and execute it. My for loop is for i in 1, 200, 400, 600, 800, 1000, 1200,......100000 do ... .. .. done As you could see there is an increment of 200 in each for loop until it reaches 100,000 Instead of specifying all the... (8 Replies)
Discussion started by: Lucky Ali
8 Replies

7. Shell Programming and Scripting

Averaging in increments using awk & head/tail

Hi, I only have a very limited understanding and experience with writing code and I was hoping I could get some help. I have a dataset of two columns (txt format, numbers in each row separated by a tab) Eg. 1 5 2 5 3 6 4 7 5 6 6 6 7 ... (5 Replies)
Discussion started by: Emred_Skye
5 Replies

8. UNIX for Dummies Questions & Answers

Want to process file in 1000 record increments

I have a file that varies in the # of records. I want to read 1000 records, do something, read the next 1000 records, do something, going in 1000 increment chunks, and then finish up with whatever is left over at end of file. (1 Reply)
Discussion started by: Tsamp
1 Replies

9. UNIX and Linux Applications

Any idea on 3 Octet IP address ?

Hi All, I found my weblog contain entries like 121.23.3 Instead of four octet. I am quite confused is it possible to have 3 octet ip at all ?? Is it generating by any program and hittng the website ? Is it a subdomain ? Please tell me your understanding on it ? Thanks (4 Replies)
Discussion started by: jambesh
4 Replies

10. Shell Programming and Scripting

Working with field increments

I have a new challenge that I need some help with. Each morning I have two files that contain working units and failed units that I join together to form file3 which is FTP to server for comparison against billing system. My problem, I would like to take joined data in file3 and add a field... (2 Replies)
Discussion started by: greengrass
2 Replies
Login or Register to Ask a Question