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?