반응형

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
:
반응형

'Open Command Line' opens a command line at the root of the project. Support for all consoles such as CMD, PowerShell, Bash, etc. Provides syntax highlighting, Intellisense and execution of .cmd and .bat files.


This extension adds a new command to the project context menu that will open a command prompt on the project's path. If the solution node is selected in Solution Explorer, then a console will open at the root of the .sln file.


Open Command LIne은 작업 중인 Visual Studio 프로젝트 폴더에서 바로 command prompt를 열 수 있게 해주는 extension 입니다.

CMD, PowerShell, Bash등을 지원합니다.


Run Tools - Extensions and Updates...


Search 'Open Command Line' on Online tab and click Download.


Installation starts when Visual Studio closes.


Close Visual Studio and click Modify on VSIX Installer.


Install it.


Click Close.




Right-click on Solution Explorer - Open Command Line - Default(cmd) (Shortcut: Alt + Space)


Command Prompt opens on the project's path.


Right-click on Solution Explorer - Open Command Line - Settings...


You can change settings.




반응형
Posted by J-sean
: