반응형

2022.01.04 - [C#] - C# Wireless Network Adapter Disable/Enable - 무선 네트워크 어댑터 활성화/비활성화 1

의 소스를 조금 더 심플하게 수정해 보자.

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
using System.Management;
 
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ListAllNetworkAdapters();
        }
 
        private static void ListAllNetworkAdapters()
        {
            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2""SELECT * FROM Win32_NetworkAdapter");
 
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["Name"].ToString().Contains("Wireless"))
                    {
                        Console.WriteLine("-----------------------------------");
                        Console.WriteLine("Win32_NetworkAdapter Instance");
                        Console.WriteLine("-----------------------------------");
                        Console.WriteLine("Name: {0}", queryObj["Name"]);
                        Console.WriteLine("NetEnabled: {0}", queryObj["NetEnabled"]);
 
                        if ((bool)queryObj["NetEnabled"])
                        {
                            queryObj.InvokeMethod("Disable"null); // 관리자 권한 실행 필요
                            Console.WriteLine("Disabled.");
                        }
                        else
                        {
                            queryObj.InvokeMethod("Enable"null); // 관리자 권한 실행 필요
                            Console.WriteLine("Enabled.");
                        }
 
                        Console.WriteLine("-----------------------------------");
                    }
                }
            }
            catch (ManagementException e)
            {
                Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
            }
        }
    }
}
 

 

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

 

활성화 되어 있던 와이파이가 표시되고 비활성화 되었다.

 

'사용 안 함' 상태에서 프로그램을 실행하면 '사용함' 상태로 바뀐다.

※ 이 프로그램은 관리자 권한으로 실행해야 한다.

 

반응형
Posted by J-sean
:
반응형

2022.01.04 - [C#] - C# Finding All Network Adapters Using WMI - 모든 네트워크 어댑터 찾기의 내용을 기본으로 무선 네트워크(Wi-Fi) 어댑터를 활성화/비활성화 하는 프로그램을 만들어 보자.

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
using System.Management;
 
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string name = "Wireless";
            ListAllNetworkAdapters(name);
        }
 
        private static void ListAllNetworkAdapters(string name)
        {
            ManagementObjectSearcher networkAdapterSearcher = new ManagementObjectSearcher("root\\cimv2", $"select * from Win32_NetworkAdapter where name like '%{name}%'");
            ManagementObjectCollection objectCollection = networkAdapterSearcher.Get();
 
            Console.WriteLine("There are {0} network adapaters:\n", objectCollection.Count);
 
            foreach (ManagementObject networkAdapter in objectCollection)
            {
                PropertyDataCollection networkAdapterProperties = networkAdapter.Properties;
                foreach (PropertyData networkAdapterProperty in networkAdapterProperties)
                {
                    if (networkAdapterProperty.Value != null)
                    {
                        Console.WriteLine("Network adapter property name: {0}", networkAdapterProperty.Name);
                        Console.WriteLine("Network adapter property value: {0}", networkAdapterProperty.Value);
                    }
                }
                Console.WriteLine("--------------------------------------------------------------------\n");
 
                Console.WriteLine($"{networkAdapterProperties["Name"].Value} enabled: {networkAdapterProperties["NetEnabled"].Value}");
                if ((bool)networkAdapterProperties["NetEnabled"].Value)
                {
                    networkAdapter.InvokeMethod("Disable"null); // 관리자 권한 실행 필요
                    Console.WriteLine("Disabled.");
                }
                else
                {
                    networkAdapter.InvokeMethod("Enable"null); // 관리자 권한 실행 필요
                    Console.WriteLine("Enabled.");
                }
            }
        }
    }
}
 

 

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

 

시스템에 있는 모든(한 개) 와이파이 어댑터의 정보가 출력되고 '사용 안 함' 상태로 변경된다. (아래 그림 참조)

 

'사용 안 함' 상태에서 프로그램을 실행하면 '사용함' 상태로 변경된다.

※ 이 프로그램은 관리자 권한으로 실행해야 한다.

 

반응형
Posted by J-sean
:
반응형

nRF24L01 모듈은 Serial Peripheral Interface(SPI) 프로토콜을 사용하여 2.4GHz 무선 통신이 가능하다.


중국에서 구매한 nRF24L01 모듈 2개.


8개의 핀이 있다.


nRF24L01의 핀맵.


아두이노의 핀맵. nRF24L01과 연결할 핀을 확인 한다.



이렇게 연결 한다.


[nRF24L01 - Arduino]

VCC - 3.3V

GND - GND

CSN - 8

CE - 7

MOSI - 11

SCK - 13

IRQ - N/A

MISO - 12


통신을 해야 하므로 2개 모두 연결해 준다.


수신 프로그램을 컴파일 하고 아두이노에 업로드 한다.


송신 프로그램을 컴파일 하고 다른 아두이노에 업로드 한다.



수신 프로그램이 업로드된 아두이노의 시리얼 모니터를 확인해 보자.

통신이 잘 안된다면 10μF 커패시터를 연결 하고 3.3V 외부 전원을 사용 하자.


GND is the Ground Pin. It is usually marked by encasing the pin in a square so it can be used as a reference for identifying the other pins.


VCC supplies power for the module. This can be anywhere from 1.9 to 3.9 volts. You can connect it to 3.3V output from your Arduino. Remember connecting it to 5V pin will likely destroy your nRF24L01+ module!


CE (Chip Enable) is an active-HIGH pin. When selected the nRF24L01 will either transmit or receive, depending upon which mode it is currently in.


CSN (Chip Select Not) is an active-LOW pin and is normally kept HIGH. When this pin goes low, the nRF24L01 begins listening on its SPI port for data and processes it accordingly.


SCK (Serial Clock) accepts clock pulses provided by the SPI bus Master.


MOSI (Master Out Slave In) is SPI input to the nRF24L01.


MISO (Master In Slave Out) is SPI output from the nRF24L01.


IRQ is an interrupt pin that can alert the master when new data is available to process.


반응형
Posted by J-sean
: