forked from icedeng/EasyIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEasyIP.c
103 lines (103 loc) · 2.53 KB
/
EasyIP.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 3
char *NAME[N],*IP[N],*GW[N],*YM[N],*DNS1[N],*DNS2[N],*NET[N],TEMP[1000];
void DELETE ( char *data )
{
char *a;
for ( a=data ; *a!= '\0' ; a++)
{
if ( *a == '\n' )
*a = '\0';
}
}
void EDIT()
{
int i,a;
FILE *add;
putchar('\n');
for ( i = 1 ; i <= N ; i++ )
printf("%d.%s" , i , NAME[i-1] );
putchar('\n');
printf("1.Add\n2.Delete\n3.Open with Notepad\n0.Back to Menu\n");
scanf("%d",&a);
if ( a == 3 )
system ("IP.txt");
if ( a == 0 )
{
putchar ( '\n' );
return;
}
EDIT();
}
void CLEAR ()
{
system ("netsh interface ipv4 set address ±¾µØÁ¬½Ó source=dhcp\nnetsh interface ipv4 set address ÎÞÏßÍøÂçÁ¬½Ó source=dhcp" );
}
void PrintMenu()
{
int i,choice;
FILE *fp;
if ( !( fp = fopen ( "IP.txt" , "r") ) ) exit(0);
for ( i = 0 ; i < N ; i++ )
{
NAME[i] = (char*) malloc ( 20 * sizeof(char) );
IP[i] = (char*) malloc ( 20 * sizeof(char) );
GW[i] = (char*) malloc ( 20 * sizeof(char) );
YM[i] = (char*) malloc ( 20 * sizeof(char) );
DNS1[i] = (char*) malloc ( 20 * sizeof(char) );
DNS2[i] = (char*) malloc ( 20 * sizeof(char) );
NET[i] = (char*) malloc ( 20 * sizeof(char) );
printf ( "%d:" , i+1 );
fputs( fgets ( NAME[i] , 20 , fp ) , stdout );
DELETE ( fgets ( IP[i] , 20 , fp ) );
DELETE ( fgets ( GW[i] , 20 , fp ) );
DELETE ( fgets ( YM[i] , 20 , fp ) );
DELETE ( fgets ( DNS1[i] , 20 , fp ) );
DELETE ( fgets ( DNS2[i] , 20 , fp ) );
DELETE ( fgets ( NET[i] , 20 , fp ) );
}
fclose ( fp );
printf ( "%d:Auto\n%d:Edit\n0:Exit\n" , N+1 ,N+2 );
scanf( "%d" , &choice );
if ( choice == 0 )
exit(0);
if ( choice < N+1 )
{
strcpy ( TEMP , "netsh interface ipv4 set dnsservers name=" );
strcat ( TEMP , NET[choice-1] );
strcat ( TEMP , " static " );
strcat ( TEMP , DNS1[choice-1] );
strcat ( TEMP , " primary validate=no" );
system(TEMP);
strcpy ( TEMP , "netsh interface ipv4 add dnsservers ");
strcat ( TEMP , NET[choice-1] );
strcat ( TEMP , " ");
strcat ( TEMP , DNS2[choice-1] );
strcat ( TEMP , " validate=no\n" );
system(TEMP);
strcpy ( TEMP , "netsh interface ipv4 set address ");
strcat ( TEMP , NET[choice-1] );
strcat ( TEMP , " static ");
strcat ( TEMP , IP[choice-1] );
strcat ( TEMP , " " );
strcat ( TEMP , YM[choice-1] );
strcat ( TEMP , " " );
strcat ( TEMP , GW[choice-1] );
CLEAR ();
system(TEMP);
exit ( 0 );
}
if ( choice == N+1 )
CLEAR ();
if ( choice == N+2 )
EDIT();
PrintMenu();
}
int main()
{
while(1)
PrintMenu();
return 0;
}