Windows 7 network adapter device name using winpcap

networkingwindows 7winpcap

I am trying to use winpcap for an application that is to be used on multiple servers in a production line. One thing that annoys me so far is the Windows 7 device naming convention, which is a long hex string and changes from server to server (i.e. \Device\NPF_{6F2E340D-FD43-4505-81C2-735716D02F15} (Linux makes this easier with just the eth0, eth1, … convention). Since each server will be using 5 network adapters, I would like to keep from having to keep a configuration file with the device names or keep from changing the source code to accommodate the device name changes. In addition, the cat5 hook up will be going to different devices on separate networks and the port assignments should always stay the same per drawing.

So my question is, is there some easy way to manage these device names under windows, such as being able to easily rename them somehow in the registry? When I looked in the registry, the hex string is shown in many entries and also shows up in folder names, so I was not sure if that would become some hassle to change or not. Or perhaps, is there a way with winpcap to grab the friendly name of a device that one can set via the network connections page and get the hex device name result that way (similar to findalldev_ex()). Any other suggestions are also welcome.

PS: I know I can use bind() to bind to ip and ports or use winsock etc, but the application and hardware interfacing to other devices is complicated due to multiple network adapters needing to have the same IP address and that conflicts in windows, hence the winpcap option in promiscuous mode creating all raw messages.

Best Answer

How do I get a network connection's "Connection Name"?

On Windows getmac can be used to retrieve both the "Connection Name" (friendly name) and the "Transport Name" (GUID).

getmac /fo csv /v

Example output:

"Connection Name","Network Adapter","Physical Address","Transport Name"
"Local Area Connection","Realtek PCIe GBE Family Controller","F0-BF-97-62-95-5D","\Device\Tcpip_{45B9E87F-83FB-4829-A751-6B62656CC1A8}"
"Wireless Network Connection","Atheros AR9285 Wireless Network Adapter","CC-AF-78-B2-4C-09","\Device\Tcpip_{B108BB0B-CCDC-4ACA-9DFE-5A2F17BC138D}"
"Bluetooth Network Connection","Bluetooth Device (Personal Area Network)","CC-AF-78-B2-4C-0A","Media disconnected"

How do I rename a connection?

netsh can be used to rename a network connection.

netsh interface set interface name="Local Area Connection" newname="New Name"

How can I automate all of this?

You can use the above commands in a batch file when installing your product to automatically create a custom local configuration file.


Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • getmac - Display the Media Access Control (MAC) address and list of network protocols associated with each address for all network cards in each computer, either locally or across a network.
  • netsh - Configure Network Interfaces, Windows Firewall, Routing & remote access.
Related Question