How to find your IP address on Windows ascii.jp?
Several ways to find out the IP address of your machine
Do you know the IP address of the machine you are currently using?Or do you know how to find out?To check the IP address, IPCONFIG.EXE commands, or control panels, "Network and Sharing Center", and Windows 10, "Settings" → "Network and Internet" → "Network status".
There are several ways to check the IP address on Windows.One is IPCONFIG.EXE, the other is the network and shared center of the control panel, and the "state" of the "network and the Internet".
The IPCONFIG command displays multiple network interfaces.At this time, the user selects the appropriate interface from the knowledge he has and "sees" the IP address displayed there.For example, if you set a network router on your own, you know the network address used in LAN, and you recognize the one that suits it as an IP address of the corresponding machine.
In the control panel network and shared centers, the Windows is a little more "intelligent", determines whether the Internet is connected to each of the network interfaces, and displays only the network adapter connected to the Internet.It is.
At the control panel network and shared centers, network adapters that are not connected to the Internet such as Bluetooth can be eliminated, but indicated network devices related to virtual network switches that are not connected to the Internet are displayed.
Therefore, there are fewer network adapters displayed than the IPCONFIG command.Nevertheless, it displays adapters made of network switches for virtual machines.
In Windows 10 "Settings" → "Network and Internet" → "Network Condition", only physical network connected to the Internet is displayed.It seems that it is judging whether it is a virtual network interface created with a network switch.
So how do these decisions make?How can I know my right IP address used for Internet connection without knowledge, such as router settings or LAN network addresses?
What is the "correct" IP address?
Being connected to the Internet must always be able to communicate with the gateway (Gateway, router).This is called "default route", and its destination router is called default Gateway.The network adapter that leads to the default route is communicated with the Internet, and the IP address can be said to be the "correct IP address."
Some PCs have two network interfaces, Ethernet and Wi-Fi, but Windows connection managers use Ethernet (wired) by default.When both wired and wireless can be used when starting Windows, Windows checks if the Internet can be connected with Ethernet first (this is confirmed whether it can be connected to a Microsoft specified site).Examining the wireless LAN side is when the Ethernet is not available or is not connected to the Internet.However, it is possible for users to enable two network interfaces, wired and wireless.
In addition, when Hyper-V is enabled, a virtual network switch is created, and a virtual network interface for connecting the running Windows on the host side to the virtual machine side is displayed.This is also assigned an IP address.In addition, Terodo, which converts IPv4 and IPv6 via a server, is also realized using a network interface.
Also, if the compatible device is not connected, it will not be displayed on the IPCONFIG, but it is also possible to connect to the Internet from Bluetooth.This is displayed in "Control Panel" → "Network and Sharing Center" → "Change Adapter Settings" → "Network Connection".Windows has many network adapters, in some cases, have an IP address.It is necessary to select a "correct IP address" from this without the knowledge of the router for Internet connection.
There are several clues that can be used.One is the default route mentioned above.At least a network adapter that is not connected to the default route is not directly connected to the Internet.The other is to have an IP address.In the first place, we are looking for the correct IP address, so we can ignore network adapters that are not assigned to IP addresses.
Get information on the network interface for the time being
There are several ways to get information on the network adapter.One is.This is a method of enumerating network adapters using Net Framework.but,.How to use Net Framework is quite troublesome.This is because it is a fairly low -level API considering versatility, so it is necessary to combine multiple APIs to follow the information.For example, the default route is managed as routing information, so it cannot be obtained directly from the Network Adapter API, and it is necessary to check the corresponding relationship between routing information and network adapter information.
If this becomes PowerShell, it will be much easier.PowerShell is.It is realized using Net Framework, but because it is for system management, IP addresses and network adapters can be handled in a relatively abstract format.However, this method only works in PowerShell.
The other is to use the system management function provided by Windows.Assuming a large number of PCs operations in companies and the like, recent OSs can extract various information in certain procedures.Windows provides a mechanism called CIM/WIM to manage the status and information of such equipment.
CIM is an abbreviation of "Common Information Model" and is an object model of the IT management target created by an organization called DMTF (Distributed Management Task Force).For example, the storage device, the network interface, and the management information that it should have is defined as an object (actually XML).
In this way, by converting the management target as an industry group, the exchange between the system management tool and the platform can be used as a certain procedure.In CIM, the network interface has a name and has information such as physical media type.By doing so, although the connection part with the platform is different, the number of platforms is possible by making the information flowing above it constant.However, CIM abstracts individual different physical devices, so it may only be vague information from the actual management work.
WMI (Windows Managiment Interface) is one of the implementation of this CIM on Windows.The story is confusing, so I will explain it simply, but in Windows, this function was named WMI, but the API was added when the access protocol was changed to a secure one, and the name was called CIM.In the first place, WMI is one of the CIMs, and the access method is only different.In order to distinguish between the original CIM and Windows, the Windows one is described as WMI/CIM.
Windows allows you to take out various management information using WMI/CIM objects.Among them, there are things related to network interfaces and IP addresses.Windows has an API for handling this WMI/CIM.The PowerShell described above also has a command that supports this API.This time, I will use this to see it.This method is a standard method of WMI/CIM, so you can create a program with the same idea in other languages.This function is "Get-Ciminstace" used when searching for Win32 applications (how to check the installation status of Win32 applications on Windows).
Using this, use a class called "Win32_networkAdapterConfiguration" this time.This class has information such as the name of the network adapter, the IP address, the gateway dress, and the subnet.For this reason, it is a convenient class to check the network connected to the Windows network interface.Specifically, as follows.
The get-ciminstance command gives you information about the network interface.By adding conditions such as assignment of IP addresses and default routes, only network adapters connected to the Internet can be extracted.
Get-ciminstance -class win32_networkadapterconfiguration |.IPenabled -eq "True" -and $ _ _.Defaultipgateway}
In front of the pipe symbol "|", the information of the network adapter is obtained, and the back is the part that has an IP address from it and has a default route (default gateway).
If you take out the iPaddress property of the object output by this command, you can get the "correct IP address".Please note that the results include not only IPv4 but also IPv6 addresses and multiple IP addresses.
(Get-ciminstance -class win32_networkadapterconfiguration |.IPenabled -eq "True" -and $ _ _.Defaultipgateway}).IPaddress
According to the actual investigation, you can get the Internet connection IP address in most cases.However, if you connect to the Ethernet while connecting by wireless LAN, both may temporarily connect to the Internet.
After a while, the Windows connection manager will cut the wireless LAN, but both will be connected for about one minute.At this time, both have "correct IP addresses", so they cannot be judged.After a while, the wireless LAN will be cut, so only one Internet connection will return.At the moment, the above method seems to be the easiest way to get the correct IP address.