반응형

ipconfig 명령을 이용해 IP 주소 구성을 삭제 하거나 갱신하는 프로그램을 만들어 보자.

IP 주소 구성 삭제시 인터넷 연결을 끊을 수 있다.

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
using System.Diagnostics;
using System.Security;
 
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            SetInternetConnection("release"); // 인터넷 연결 해제
            //SetInternetConnection("renew"); // 인터넷 연결
        }
 
        static void SetInternetConnection(string command)
        {
            try
            {
                ProcessStartInfo processStartInfo = new ProcessStartInfo()
                {
                    FileName = "cmd.exe",
                    Arguments = "/c ipconfig /" + command,
                    WindowStyle = ProcessWindowStyle.Hidden
                };
 
                //ProcessStartInfo processStartInfo = new ProcessStartInfo();
                //processStartInfo.FileName = "cmd.exe";
                //processStartInfo.Arguments = "/c ipconfig /" + command;
                //processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
 
                Process.Start(processStartInfo);
                // This class contains a link demand at the class level that applies
                // to all members. A SecurityException is thrown when the immediate
                // caller does not have full-trust permission.
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Security Exception: {0}", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
            }
        }
    }
}
 

 

소스를 입력하고 빌드한다.

 

프로그램을 실행하면 인터넷 연결이 끊긴다.

 

SetInternetConnection() 호출 주석을 바꾸면 인터넷이 연결된다.

 

반응형
Posted by J-sean
: