Beginner :: Script to configure Cisco Switch

This is a discussion on Beginner :: Script to configure Cisco Switch within the C Programming forums, part of the General Programming Boards category; Hi there... 1st of all, i'm beginner with C programming because my job scope focus on networking... I'm doing C ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    Beginner :: Script to configure Cisco Switch

    Hi there...
    1st of all, i'm beginner with C programming because my job scope focus on networking...

    I'm doing C programming just to solve my Cisco switch configuration that require repeating task.. Refer below for info ::

    interface vlan 1
    ip address 172.22.1.253 255.255.255.0
    ip access-group Deny_HTTP_Vlan1 in
    ip helper-address 172.20.1.246
    glbp 1 ip 172.22.1.254
    glbp 1 priority 110
    glbp 1 preempt
    exit
    interface vlan 2
    ip address 172.22.11.253 255.255.255.0
    ip access-group Deny_HTTP_Vlan1 in
    ip helper-address 172.20.1.246
    glbp 2 ip 172.22.11.254
    glbp 2 priority 110
    glbp 2 preempt
    exit
    For your info, i need to repeat the same command as above up to 40 times. So, for fast solution , i create simple C programming as below ::

    The Rules
    ----------------
    1- Vlan ID is sequence (From 1 until 40)
    2- IP address for the 3rd octet is always plus 1 (ip+1) . The start number of ip is 10.
    3- If VLAN ID grater than 40 and IP address greater than 50, go to the next rules.
    4- If user input other than above, return "Not Valid"
    So this is my coding ::

    Code:
    #include <stdio.h>
    
    int main()
    
    {
    
    int vlan,ip;
    for (vlan=1,ip=10;vlan<=40,ip<=50;vlan++,ip=ip+1);
    {
        printf( "Please enter your vlan number :" );
        scanf( "%d", &vlan );
        printf("Please enter your 3rd octet ip \n Example (172.22.X.253):");
        scanf("%d", &ip);
    }
    if ( vlan <= 40 && ip <= 50 )
    {
         printf ("interface vlan %d\n",vlan);
         printf ("ip address 172.22.%d.253 255.255.255.0\n ",ip);
         printf ("ip access-group Deny_HTTP_Vlan1 in\n");
         printf ("ip helper-address 172.20.1.254\n");
         printf ("glbp %d ip 172.22.%d.254\n",vlan,ip);
         printf ("glbp %d priority 110\n",vlan);
         printf ("glbp %d preempt\n",vlan);
         printf ("exit\n");
    }
    
      else if ( vlan >= 41 && ip >= 51 )
    {
         printf("interface vlan %d\n",vlan );
         printf("ip address 172.22.%d.253 255.255.255.0\n",ip);
    }
      else
    {
        printf( "Not Valid\n" );
    
    }
      return 0;
    Problem

    My problem is unable to repeat / loop the output up to 40 times. Actually what is the problem?
    Last edited by apit; 09-07-2009 at 07:33 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Put your output statements inside the loop so that they happen each time?

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    2
    i can't get it?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by apit View Post
    i can't get it?
    Do you know what the words inside and outside mean? Put your if and the print and all that inside the loop and not outside the loop.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,651
    Forget the loop for a moment. Get the program to work correctly *once* and then proceed as necessary. It also might be a good idea to put that into a function and just call the function in a loop, to simplify things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  2. Script in games
    By Shakti in forum Game Programming
    Replies: 7
    Last Post: 09-27-2006, 12:27 AM
  3. compiling a program that has no configure script
    By serfurj in forum Linux Programming
    Replies: 9
    Last Post: 02-09-2005, 09:53 AM
  4. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM
  5. Creating a configure script
    By WebmasterMattD in forum Linux Programming
    Replies: 1
    Last Post: 05-18-2002, 01:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21