Command to find network interface for IPNo internet on Windows 7 virtual pc on Windows 7 with NAT...

Why didn’t Eve recognize the little cockroach as a living organism?

Can you take a "free object interaction" while incapacitated?

Why can't I get pgrep output right to variable on bash script?

Why does the frost depth increase when the surface temperature warms up?

Calculate Pi using Monte Carlo

Friend wants my recommendation but I don't want to give it to him

Are hand made posters acceptable in Academia?

How do I lift the insulation blower into the attic?

Can a Knock spell open the door to Mordenkainen's Magnificent Mansion?

Strange behavior in TikZ draw command

C++ lambda syntax

I keep switching characters, how do I stop?

Would this string work as string?

Can you describe someone as luxurious? As in someone who likes luxurious things?

What do the positive and negative (+/-) transmit and receive pins mean on Ethernet cables?

What is the meaning of "You've never met a graph you didn't like?"

What is the tangent at a sharp point on a curve?

Checking @@ROWCOUNT failing

Pre-Employment Background Check With Consent For Future Checks

Make a Bowl of Alphabet Soup

Rendered textures different to 3D View

Did I make a mistake by ccing email to boss to others?

Exposing a company lying about themselves in a tightly knit industry (videogames) : Is my career at risk on the long run?

PTIJ: Which Dr. Seuss books should one obtain?



Command to find network interface for IP


No internet on Windows 7 virtual pc on Windows 7 with NAT configurationNo internet connection, can ping fineHow to use a different Ethernet connectionResetting gone wrongWireless Network Connectivity Issues happen randomlyTroubleshooting 1 modem 1 switch 2 wifi routers (one-2.4ghz & one-5ghz)Why does my hostname resolve to IP of virtual nic and not the physical one?VirtualBox Host Mac not able to connect to VirtualBox Guest Windows 7Tp-link router DNS issuedefault gateway after network card damage













9















With ipconfig I can show the list of network adapters and their settings, e.g. the IP address.



I'm looking for a reverse command that displays the name of the network adapter for a given IP address.



I have tried filtering the output of ipconfig with a command like ipconfig | find "192.168.2.4" but then the adapter name is gone.



My output of ipconfig is (the tricky part seems that I have several addresses on one adapter here):



Windows IP Configuration


Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::xxxx:xxxx:xxxx:xxxx%11
IPv4 Address. . . . . . . . . . . : 192.168.2.4
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.178.20
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.178.1
192.168.2.1

Ethernet adapter VMware Network Adapter VMnet1:
...









share|improve this question

























  • For a given local address, or to find out what interface routing uses to reach a particular remote address?

    – Ben Voigt
    Nov 22 '15 at 14:11











  • @BenVoigt: it's an address assigned to a network interface, so the result should be one adapter only. If it were about routing, the result could be many adapters (potentially with different metrics).

    – Thomas Weller
    Nov 22 '15 at 17:49
















9















With ipconfig I can show the list of network adapters and their settings, e.g. the IP address.



I'm looking for a reverse command that displays the name of the network adapter for a given IP address.



I have tried filtering the output of ipconfig with a command like ipconfig | find "192.168.2.4" but then the adapter name is gone.



My output of ipconfig is (the tricky part seems that I have several addresses on one adapter here):



Windows IP Configuration


Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::xxxx:xxxx:xxxx:xxxx%11
IPv4 Address. . . . . . . . . . . : 192.168.2.4
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.178.20
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.178.1
192.168.2.1

Ethernet adapter VMware Network Adapter VMnet1:
...









share|improve this question

























  • For a given local address, or to find out what interface routing uses to reach a particular remote address?

    – Ben Voigt
    Nov 22 '15 at 14:11











  • @BenVoigt: it's an address assigned to a network interface, so the result should be one adapter only. If it were about routing, the result could be many adapters (potentially with different metrics).

    – Thomas Weller
    Nov 22 '15 at 17:49














9












9








9


1






With ipconfig I can show the list of network adapters and their settings, e.g. the IP address.



I'm looking for a reverse command that displays the name of the network adapter for a given IP address.



I have tried filtering the output of ipconfig with a command like ipconfig | find "192.168.2.4" but then the adapter name is gone.



My output of ipconfig is (the tricky part seems that I have several addresses on one adapter here):



Windows IP Configuration


Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::xxxx:xxxx:xxxx:xxxx%11
IPv4 Address. . . . . . . . . . . : 192.168.2.4
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.178.20
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.178.1
192.168.2.1

Ethernet adapter VMware Network Adapter VMnet1:
...









share|improve this question
















With ipconfig I can show the list of network adapters and their settings, e.g. the IP address.



I'm looking for a reverse command that displays the name of the network adapter for a given IP address.



I have tried filtering the output of ipconfig with a command like ipconfig | find "192.168.2.4" but then the adapter name is gone.



My output of ipconfig is (the tricky part seems that I have several addresses on one adapter here):



Windows IP Configuration


Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::xxxx:xxxx:xxxx:xxxx%11
IPv4 Address. . . . . . . . . . . : 192.168.2.4
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.178.20
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.178.1
192.168.2.1

Ethernet adapter VMware Network Adapter VMnet1:
...






windows networking ip batch-file ip-address






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '15 at 3:35









boot13

5,19131940




5,19131940










asked Nov 21 '15 at 23:38









Thomas WellerThomas Weller

3,06563163




3,06563163













  • For a given local address, or to find out what interface routing uses to reach a particular remote address?

    – Ben Voigt
    Nov 22 '15 at 14:11











  • @BenVoigt: it's an address assigned to a network interface, so the result should be one adapter only. If it were about routing, the result could be many adapters (potentially with different metrics).

    – Thomas Weller
    Nov 22 '15 at 17:49



















  • For a given local address, or to find out what interface routing uses to reach a particular remote address?

    – Ben Voigt
    Nov 22 '15 at 14:11











  • @BenVoigt: it's an address assigned to a network interface, so the result should be one adapter only. If it were about routing, the result could be many adapters (potentially with different metrics).

    – Thomas Weller
    Nov 22 '15 at 17:49

















For a given local address, or to find out what interface routing uses to reach a particular remote address?

– Ben Voigt
Nov 22 '15 at 14:11





For a given local address, or to find out what interface routing uses to reach a particular remote address?

– Ben Voigt
Nov 22 '15 at 14:11













@BenVoigt: it's an address assigned to a network interface, so the result should be one adapter only. If it were about routing, the result could be many adapters (potentially with different metrics).

– Thomas Weller
Nov 22 '15 at 17:49





@BenVoigt: it's an address assigned to a network interface, so the result should be one adapter only. If it were about routing, the result could be many adapters (potentially with different metrics).

– Thomas Weller
Nov 22 '15 at 17:49










7 Answers
7






active

oldest

votes


















7














How do I display the name of a network adapter for a given IP address?



This solution does not require any external commands (pcre2grep, sed, etc).



Use the following batch file (getname.cmd):



@echo off
setlocal
setlocal enabledelayedexpansion
set "_adapter="
set "_ip="
for /f "tokens=1* delims=:" %%g in ('ipconfig /all') do (
set "_tmp=%%~g"
if "!_tmp:adapter=!"=="!_tmp!" (
if not "!_tmp:IPv4 Address=!"=="!_tmp!" (
for %%i in (%%~h) do (
if not "%%~i"=="" set "_ip=%%~i"
)
set "_ip=!_ip:(Preferred)=!"
if "!_ip!"=="%1" (
@echo !_adapter!
)
)
) else (
set "_ip="
set "_adapter=!_tmp:*adapter =!"
)
)
endlocal


Usage:



getname ipaddress


Example:



F:test>getname 192.168.42.78
Local Area Connection 2
F:test>




Further Reading





  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.


  • for /f - Loop command against the results of another command.


  • ipconfig - Configure IP (Internet Protocol configuration)






share|improve this answer


























  • That's interesting David... almost programming! Your idea made me think, I'm posting my batch solution

    – SΛLVΘ
    Nov 23 '15 at 9:30






  • 1





    @SalvoF It is programming. Batch has variables, goto, for, if, functions, macros ... what more do you need? ;)

    – DavidPostill
    Nov 23 '15 at 9:36











  • I didn't know this until I wondered what has happened to my network config :-)

    – Thomas Weller
    Nov 23 '15 at 21:39











  • @ThomasWeller Do you know yet how it happened?

    – DavidPostill
    Nov 23 '15 at 21:40











  • Not exactly. It certainly happened when I set up my 2 DSL lines. I have 2 DSL modems. They competed with DCHP, so I set up a fixed address. But that only used one DSL modem, ignoring the second. Some colleages made it work for 2 modems, potentially by setting 2 fixed addresses. Since that time, some of my batch files (and other stuff) is not working as expected any more. Hence the question.

    – Thomas Weller
    Nov 23 '15 at 21:56



















6














You could use this PS one liner:



$addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}


To use it directly from command line:



powershell "$addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}"


or if you want to reuse it put it in a script and make the address a parameter



Edit: to get a name as it shows in Win/Ipconfig:



$addr='192.168.2.4'; 
$netconf = get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr};
$netconf |% {$_.GetRelated("win32_NetworkAdapter")} | select NetConnectionID |%{$_.NetConnectionID}


(the assignment to intermediary variables is only to make it a bit more readable)






share|improve this answer


























  • This is cool, and it returns HW name. On my system $powershell is undefined though, I launch those commands with powershell -c from command prompt. On PS command line 1st one-liner runs as well.

    – SΛLVΘ
    Nov 22 '15 at 19:34






  • 1





    @ThomasWeller which in fact is a name of your network adapter as you per your question. But let me check, logical name should be obtainable as well

    – wmz
    Nov 23 '15 at 21:27






  • 2





    It's on another table @wmz. PS rocks though: powershell "$ip = '192.168.2.4';foreach($int in (gwmi Win32_NetworkAdapter)) {gwmi Win32_NetworkAdapterConfiguration -Filter """Index = $($int.index)""" | ? {$_.IPAddress -contains $ip} | % {$int.NetConnectionID} }"

    – SΛLVΘ
    Nov 23 '15 at 23:00








  • 1





    @ThomasWeller Check my edit. That was tougher than I thought! Fortunately PS supports GetRelated which eases Associators of methods a bit.

    – wmz
    Nov 23 '15 at 23:08






  • 1





    @SalvoF Yup I found it

    – wmz
    Nov 23 '15 at 23:12



















4















I'm looking for a reverse command that displays the name of the
network adapter for a given IP address.




Based on everything I tried, this should work seems you say you need to get this information ONLY from the IP address which you already specify in your example.



INTERACTIVE PROMPT FOR IP ADDRESS TO GET NETWORK CONNECTION NAME



(Use WMIC and some batch FOR loop token and delim parsing to get the network connection name for a specified IP address.)



(The result value will echo to a command window and a message box window. It's all batch script but dynamically builds some VBS script functions to simplify the process for anyone that needs.)



@ECHO ON

:SetTempFiles
SET tmpIPaddr=%tmp%~tmpipaddress.vbs
SET tmpNetConName1=%tmp%~tmpNetConName1.txt
SET tmpNetConName2=%tmp%~tmpNetConName2.txt
SET tmpBatFile=%tmp%~tmpBatch.cmd
SET tmpVBNetCon=%tmp%~tmpVBNetCon.vbs

IF EXIST "%tmpIPaddr%" DEL /F /Q "%tmpIPaddr%"
IF EXIST "%tmpNetConName1%" DEL /Q /F "%tmpNetConName1%"
IF EXIST "%tmpNetConName2%" DEL /Q /F "%tmpNetConName2%"
IF EXIST "%tmpBatFile%" DEL /Q /F "%tmpBatFile%"
IF EXIST "%tmpVBNetCon%" DEL /Q /F "%tmpVBNetCon%"

:InputBox
SET msgboxTitle=IP ADDRESS
SET msgboxLine1=Enter the IP address to get its Windows connection name
>"%tmpIPaddr%" ECHO wsh.echo inputbox("%msgboxLine1%","%msgboxTitle%")
FOR /F "tokens=*" %%N IN ('cscript //nologo "%tmpIPaddr%"') DO CALL :setvariables %%N
GOTO EOF

:setvariables
SET IPAddress=%~1
FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%A IN (`"WMIC NICCONFIG GET IPADDRESS,MACADDRESS /FORMAT:CSV | FIND /I "%IPAddress%""`) DO (SET MACAddress=%%~A)
FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%B IN (`"WMIC NIC GET MACADDRESS,NETCONNECTIONID /FORMAT:CSV | FIND /I "%MACAddress%""`) DO ECHO(%%~B>>"%tmpNetConName1%"

::: Parse Empty Lines
FINDSTR "." "%tmpNetConName1%">"%tmpNetConName2%"

::: Build Dynamic Batch with ECHO'd Network Connection Value
FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO ECHO ECHO %%~C>>"%tmpBatFile%"
IF NOT EXIST "%tmpBatFile%" GOTO :NullExit
START "" "%tmpBatFile%"

::: Build Dynamic VBS with Message Box Network Connection Value
FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO (SET vbNetconName=%%~C)
ECHO msgbox "%vbNetconName%",0,"%vbNetconName%">"%tmpVBNetCon%"
START /B "" "%tmpVBNetCon%"
EXIT /B

:NullExit
ECHO msgbox "Cannot find MAC Address, check to confirm IP Address was correct.",0,"Invalid IP">"%tmpVBNetCon%"
START /B "" "%tmpVBNetCon%"
EXIT /B




ALL ONE-LINERS



NATIVE WINDOWS ONLY WITH NETSH ALL INTERFACES (ALL IPv4 ADDRESSES)



NETSH INT IP SHOW CONFIG | FINDSTR /R "Configuration for interface.* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


enter image description here



NATIVE WINDOWS ONLY WITH IPCONFIG ALL INTERFACES (ALL IPv4 ADDRESSES)



IPCONFIG | FINDSTR /R "Ethernet* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


enter image description here





USING PCRE2GREP (per @SalvoF)



SINGLE IP ADDRESS SPECIFIED



netsh interface ipv4 show address | pcre2grep -B2 "192.168.2.4" | FIND /V "DHCP"


FIND ALL IP ADDRESSES



netsh interface ip show config | pcre2grep -B2 ^(?:[0-9]{1,3}.){3}[0-9]{1,3}$ | FIND /V "DHCP" | FIND /V "Gate" | FIND /V "Metric" | FIND /V "Subnet"


FIND ALL IP ADDRESSES (Cleaned Up Regex (per @SalvoF))



netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}"


Please note that the pcre2grep I tried is per @SalvoF [+1] as he suggested but using the.... FIND /V to remove the line above containing DHCP seems to get the desired output as you described. I used NETSH rather than IPCONFIG as well.






share|improve this answer


























  • This catches some extra information on my machines (as network masks, and such). My point was that in case you have multiple IP addresses, you cease having a "fixed" rule to get to interface name. Initial Q is: given an IP no. how do I find the interface it belongs to? I wasn't looking for all IP's.

    – SΛLVΘ
    Nov 22 '15 at 3:32








  • 1





    Thank you for your inputs! BTW, I noticed that leading and trailing lines on my side were due to language issues. To circumvent those, what do you think about this? netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}" (I cleaned the regex a bit). I'm learning a lot around this place!

    – SΛLVΘ
    Nov 22 '15 at 5:18











  • +1 Thanks for the suggestion. It still has too much output for my usage.

    – Thomas Weller
    Nov 23 '15 at 19:39



















3














To be more accurate, following OP's example, I'd use sed, which can be found under the usrlocalwbin folder of this zipped file (UnxUtils project).



ipconfig | sed -rn "/^[A-Z]/h;/192.168.2.4/{g;s/.* adapter (.*):/1/p;}"


-n suppresses non matching lines; first pattern finds any line starting with capital letter, then h puts it away on hold space; second match is on wanted IP number: at this point, line holding interface name is recalled (g), extra leading text stripped (s), and printed (p).






share|improve this answer


























  • -B4 almost works, it just leaves me with the prefix "Ethernet adapter", which does not belong to the adapter name + 4 lines of unrelated output. But the message is clear: find a tool that does it :-)

    – Thomas Weller
    Nov 22 '15 at 0:47








  • 1





    Could you update your post to show unfiltered ipconfig output? (Obfuscate or change data for privacy)

    – SΛLVΘ
    Nov 22 '15 at 0:52











  • Ok, added. It also seems to be tricky to handle adapters with multiple addresses.

    – Thomas Weller
    Nov 22 '15 at 0:58






  • 1





    That's brilliant @PJMahoney. What would be the output with multiple IP addresses though? I made an effort for a general solution by using sed; maybe your solution too can be tweaked to reach that goal.

    – SΛLVΘ
    Nov 22 '15 at 3:10











  • The sed one works if I add another | sed -rn "s/^.* adapter (.*):/1/p"

    – Thomas Weller
    Nov 23 '15 at 21:58



















2














Just for the record, here's another batch solution, it exploits delayed expansion of the %ERRORLEVEL% system variable:



@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%L in ('ipconfig') do (
echo %%L | findstr /r "^[A-Z]" 1>NUL
if !errorlevel! == 0 set "_int=%%L"
echo %%L | findstr /c:%1 1>NUL
if !errorlevel! == 0 (
set "_int=!_int::=!"
echo !_int:* adapter =!
goto:eof
)
)


It can be invoked this way: find_int.cmd 192.168.1.100






share|improve this answer


























  • Hehe. That is a neat pure batch solution. Well done ;)

    – DavidPostill
    Nov 23 '15 at 9:40











  • +1 The output is very close to what I need. Thanks

    – Thomas Weller
    Nov 23 '15 at 19:44











  • I edited the sed one-liner, leaving interface name as sole output. Of course, you can write a simple batch file for that too, passing the IP no. as argument (%1).

    – SΛLVΘ
    Nov 23 '15 at 20:19













  • @ThomasWeller, tuned this one too. Cheers!

    – SΛLVΘ
    Nov 23 '15 at 23:48



















1














Thanks for the effort everyone. It seems there are several hurdles:




  • the number of IP addresses assigned to an adapter

  • the language of the OS


All the -Bx and Regex stuff seems to break easily, so I googled for something I could implement myself and came up with the following C# program, which takes the IP address as parameter (IP2Adapter <IP>):



using System;
using System.Net.NetworkInformation;
using System.Net.Sockets;

namespace IP2Adapter
{
class Program
{
static void Main(string[] args)
{
var adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (var adapter in adapters)
{
var ipProps = adapter.GetIPProperties();
foreach (var ip in ipProps.UnicastAddresses)
{
if ((adapter.OperationalStatus == OperationalStatus.Up)
&& (ip.Address.AddressFamily == AddressFamily.InterNetwork))
{
if (ip.Address.ToString() == args[0])
Console.Out.WriteLine(adapter.Name);
}
}
}
}
}
}





share|improve this answer































    0














    On Windows 10 Powershell, this can be achieved with the following:



    Get-NetIPAddress -IPAddress '192.168.2.4' | select InterfaceAlias | %{$_.InterfaceAlias};


    This will give a result such as Wi-Fi.



    Where You can substitute InterfaceAlias for any other object property.



    To get all properties, simply omit the pipes, and run: Get-NetIPAddress -IPAddress '192.168.2.4'.



    Other network adapter related properties (such as Description) can usually be queried based on InterfaceAlias or InterfaceIndex, eg.:



    Get-NetAdapter -InterfaceAlias Wi-Fi | select InterfaceDescription | %{$_.InterfaceDescription};


    Which will give something like: Intel(R) Dual Band Wireless-AC 8265.



    Read more on the docs: https://docs.microsoft.com/en-us/powershell/module/nettcpip/get-netipaddress?view=win10-ps






    share|improve this answer










    New contributor




    MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1003746%2fcommand-to-find-network-interface-for-ip%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      7 Answers
      7






      active

      oldest

      votes








      7 Answers
      7






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      7














      How do I display the name of a network adapter for a given IP address?



      This solution does not require any external commands (pcre2grep, sed, etc).



      Use the following batch file (getname.cmd):



      @echo off
      setlocal
      setlocal enabledelayedexpansion
      set "_adapter="
      set "_ip="
      for /f "tokens=1* delims=:" %%g in ('ipconfig /all') do (
      set "_tmp=%%~g"
      if "!_tmp:adapter=!"=="!_tmp!" (
      if not "!_tmp:IPv4 Address=!"=="!_tmp!" (
      for %%i in (%%~h) do (
      if not "%%~i"=="" set "_ip=%%~i"
      )
      set "_ip=!_ip:(Preferred)=!"
      if "!_ip!"=="%1" (
      @echo !_adapter!
      )
      )
      ) else (
      set "_ip="
      set "_adapter=!_tmp:*adapter =!"
      )
      )
      endlocal


      Usage:



      getname ipaddress


      Example:



      F:test>getname 192.168.42.78
      Local Area Connection 2
      F:test>




      Further Reading





      • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.


      • for /f - Loop command against the results of another command.


      • ipconfig - Configure IP (Internet Protocol configuration)






      share|improve this answer


























      • That's interesting David... almost programming! Your idea made me think, I'm posting my batch solution

        – SΛLVΘ
        Nov 23 '15 at 9:30






      • 1





        @SalvoF It is programming. Batch has variables, goto, for, if, functions, macros ... what more do you need? ;)

        – DavidPostill
        Nov 23 '15 at 9:36











      • I didn't know this until I wondered what has happened to my network config :-)

        – Thomas Weller
        Nov 23 '15 at 21:39











      • @ThomasWeller Do you know yet how it happened?

        – DavidPostill
        Nov 23 '15 at 21:40











      • Not exactly. It certainly happened when I set up my 2 DSL lines. I have 2 DSL modems. They competed with DCHP, so I set up a fixed address. But that only used one DSL modem, ignoring the second. Some colleages made it work for 2 modems, potentially by setting 2 fixed addresses. Since that time, some of my batch files (and other stuff) is not working as expected any more. Hence the question.

        – Thomas Weller
        Nov 23 '15 at 21:56
















      7














      How do I display the name of a network adapter for a given IP address?



      This solution does not require any external commands (pcre2grep, sed, etc).



      Use the following batch file (getname.cmd):



      @echo off
      setlocal
      setlocal enabledelayedexpansion
      set "_adapter="
      set "_ip="
      for /f "tokens=1* delims=:" %%g in ('ipconfig /all') do (
      set "_tmp=%%~g"
      if "!_tmp:adapter=!"=="!_tmp!" (
      if not "!_tmp:IPv4 Address=!"=="!_tmp!" (
      for %%i in (%%~h) do (
      if not "%%~i"=="" set "_ip=%%~i"
      )
      set "_ip=!_ip:(Preferred)=!"
      if "!_ip!"=="%1" (
      @echo !_adapter!
      )
      )
      ) else (
      set "_ip="
      set "_adapter=!_tmp:*adapter =!"
      )
      )
      endlocal


      Usage:



      getname ipaddress


      Example:



      F:test>getname 192.168.42.78
      Local Area Connection 2
      F:test>




      Further Reading





      • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.


      • for /f - Loop command against the results of another command.


      • ipconfig - Configure IP (Internet Protocol configuration)






      share|improve this answer


























      • That's interesting David... almost programming! Your idea made me think, I'm posting my batch solution

        – SΛLVΘ
        Nov 23 '15 at 9:30






      • 1





        @SalvoF It is programming. Batch has variables, goto, for, if, functions, macros ... what more do you need? ;)

        – DavidPostill
        Nov 23 '15 at 9:36











      • I didn't know this until I wondered what has happened to my network config :-)

        – Thomas Weller
        Nov 23 '15 at 21:39











      • @ThomasWeller Do you know yet how it happened?

        – DavidPostill
        Nov 23 '15 at 21:40











      • Not exactly. It certainly happened when I set up my 2 DSL lines. I have 2 DSL modems. They competed with DCHP, so I set up a fixed address. But that only used one DSL modem, ignoring the second. Some colleages made it work for 2 modems, potentially by setting 2 fixed addresses. Since that time, some of my batch files (and other stuff) is not working as expected any more. Hence the question.

        – Thomas Weller
        Nov 23 '15 at 21:56














      7












      7








      7







      How do I display the name of a network adapter for a given IP address?



      This solution does not require any external commands (pcre2grep, sed, etc).



      Use the following batch file (getname.cmd):



      @echo off
      setlocal
      setlocal enabledelayedexpansion
      set "_adapter="
      set "_ip="
      for /f "tokens=1* delims=:" %%g in ('ipconfig /all') do (
      set "_tmp=%%~g"
      if "!_tmp:adapter=!"=="!_tmp!" (
      if not "!_tmp:IPv4 Address=!"=="!_tmp!" (
      for %%i in (%%~h) do (
      if not "%%~i"=="" set "_ip=%%~i"
      )
      set "_ip=!_ip:(Preferred)=!"
      if "!_ip!"=="%1" (
      @echo !_adapter!
      )
      )
      ) else (
      set "_ip="
      set "_adapter=!_tmp:*adapter =!"
      )
      )
      endlocal


      Usage:



      getname ipaddress


      Example:



      F:test>getname 192.168.42.78
      Local Area Connection 2
      F:test>




      Further Reading





      • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.


      • for /f - Loop command against the results of another command.


      • ipconfig - Configure IP (Internet Protocol configuration)






      share|improve this answer















      How do I display the name of a network adapter for a given IP address?



      This solution does not require any external commands (pcre2grep, sed, etc).



      Use the following batch file (getname.cmd):



      @echo off
      setlocal
      setlocal enabledelayedexpansion
      set "_adapter="
      set "_ip="
      for /f "tokens=1* delims=:" %%g in ('ipconfig /all') do (
      set "_tmp=%%~g"
      if "!_tmp:adapter=!"=="!_tmp!" (
      if not "!_tmp:IPv4 Address=!"=="!_tmp!" (
      for %%i in (%%~h) do (
      if not "%%~i"=="" set "_ip=%%~i"
      )
      set "_ip=!_ip:(Preferred)=!"
      if "!_ip!"=="%1" (
      @echo !_adapter!
      )
      )
      ) else (
      set "_ip="
      set "_adapter=!_tmp:*adapter =!"
      )
      )
      endlocal


      Usage:



      getname ipaddress


      Example:



      F:test>getname 192.168.42.78
      Local Area Connection 2
      F:test>




      Further Reading





      • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.


      • for /f - Loop command against the results of another command.


      • ipconfig - Configure IP (Internet Protocol configuration)







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 23 '15 at 21:34

























      answered Nov 22 '15 at 13:53









      DavidPostillDavidPostill

      107k27235269




      107k27235269













      • That's interesting David... almost programming! Your idea made me think, I'm posting my batch solution

        – SΛLVΘ
        Nov 23 '15 at 9:30






      • 1





        @SalvoF It is programming. Batch has variables, goto, for, if, functions, macros ... what more do you need? ;)

        – DavidPostill
        Nov 23 '15 at 9:36











      • I didn't know this until I wondered what has happened to my network config :-)

        – Thomas Weller
        Nov 23 '15 at 21:39











      • @ThomasWeller Do you know yet how it happened?

        – DavidPostill
        Nov 23 '15 at 21:40











      • Not exactly. It certainly happened when I set up my 2 DSL lines. I have 2 DSL modems. They competed with DCHP, so I set up a fixed address. But that only used one DSL modem, ignoring the second. Some colleages made it work for 2 modems, potentially by setting 2 fixed addresses. Since that time, some of my batch files (and other stuff) is not working as expected any more. Hence the question.

        – Thomas Weller
        Nov 23 '15 at 21:56



















      • That's interesting David... almost programming! Your idea made me think, I'm posting my batch solution

        – SΛLVΘ
        Nov 23 '15 at 9:30






      • 1





        @SalvoF It is programming. Batch has variables, goto, for, if, functions, macros ... what more do you need? ;)

        – DavidPostill
        Nov 23 '15 at 9:36











      • I didn't know this until I wondered what has happened to my network config :-)

        – Thomas Weller
        Nov 23 '15 at 21:39











      • @ThomasWeller Do you know yet how it happened?

        – DavidPostill
        Nov 23 '15 at 21:40











      • Not exactly. It certainly happened when I set up my 2 DSL lines. I have 2 DSL modems. They competed with DCHP, so I set up a fixed address. But that only used one DSL modem, ignoring the second. Some colleages made it work for 2 modems, potentially by setting 2 fixed addresses. Since that time, some of my batch files (and other stuff) is not working as expected any more. Hence the question.

        – Thomas Weller
        Nov 23 '15 at 21:56

















      That's interesting David... almost programming! Your idea made me think, I'm posting my batch solution

      – SΛLVΘ
      Nov 23 '15 at 9:30





      That's interesting David... almost programming! Your idea made me think, I'm posting my batch solution

      – SΛLVΘ
      Nov 23 '15 at 9:30




      1




      1





      @SalvoF It is programming. Batch has variables, goto, for, if, functions, macros ... what more do you need? ;)

      – DavidPostill
      Nov 23 '15 at 9:36





      @SalvoF It is programming. Batch has variables, goto, for, if, functions, macros ... what more do you need? ;)

      – DavidPostill
      Nov 23 '15 at 9:36













      I didn't know this until I wondered what has happened to my network config :-)

      – Thomas Weller
      Nov 23 '15 at 21:39





      I didn't know this until I wondered what has happened to my network config :-)

      – Thomas Weller
      Nov 23 '15 at 21:39













      @ThomasWeller Do you know yet how it happened?

      – DavidPostill
      Nov 23 '15 at 21:40





      @ThomasWeller Do you know yet how it happened?

      – DavidPostill
      Nov 23 '15 at 21:40













      Not exactly. It certainly happened when I set up my 2 DSL lines. I have 2 DSL modems. They competed with DCHP, so I set up a fixed address. But that only used one DSL modem, ignoring the second. Some colleages made it work for 2 modems, potentially by setting 2 fixed addresses. Since that time, some of my batch files (and other stuff) is not working as expected any more. Hence the question.

      – Thomas Weller
      Nov 23 '15 at 21:56





      Not exactly. It certainly happened when I set up my 2 DSL lines. I have 2 DSL modems. They competed with DCHP, so I set up a fixed address. But that only used one DSL modem, ignoring the second. Some colleages made it work for 2 modems, potentially by setting 2 fixed addresses. Since that time, some of my batch files (and other stuff) is not working as expected any more. Hence the question.

      – Thomas Weller
      Nov 23 '15 at 21:56













      6














      You could use this PS one liner:



      $addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}


      To use it directly from command line:



      powershell "$addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}"


      or if you want to reuse it put it in a script and make the address a parameter



      Edit: to get a name as it shows in Win/Ipconfig:



      $addr='192.168.2.4'; 
      $netconf = get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr};
      $netconf |% {$_.GetRelated("win32_NetworkAdapter")} | select NetConnectionID |%{$_.NetConnectionID}


      (the assignment to intermediary variables is only to make it a bit more readable)






      share|improve this answer


























      • This is cool, and it returns HW name. On my system $powershell is undefined though, I launch those commands with powershell -c from command prompt. On PS command line 1st one-liner runs as well.

        – SΛLVΘ
        Nov 22 '15 at 19:34






      • 1





        @ThomasWeller which in fact is a name of your network adapter as you per your question. But let me check, logical name should be obtainable as well

        – wmz
        Nov 23 '15 at 21:27






      • 2





        It's on another table @wmz. PS rocks though: powershell "$ip = '192.168.2.4';foreach($int in (gwmi Win32_NetworkAdapter)) {gwmi Win32_NetworkAdapterConfiguration -Filter """Index = $($int.index)""" | ? {$_.IPAddress -contains $ip} | % {$int.NetConnectionID} }"

        – SΛLVΘ
        Nov 23 '15 at 23:00








      • 1





        @ThomasWeller Check my edit. That was tougher than I thought! Fortunately PS supports GetRelated which eases Associators of methods a bit.

        – wmz
        Nov 23 '15 at 23:08






      • 1





        @SalvoF Yup I found it

        – wmz
        Nov 23 '15 at 23:12
















      6














      You could use this PS one liner:



      $addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}


      To use it directly from command line:



      powershell "$addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}"


      or if you want to reuse it put it in a script and make the address a parameter



      Edit: to get a name as it shows in Win/Ipconfig:



      $addr='192.168.2.4'; 
      $netconf = get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr};
      $netconf |% {$_.GetRelated("win32_NetworkAdapter")} | select NetConnectionID |%{$_.NetConnectionID}


      (the assignment to intermediary variables is only to make it a bit more readable)






      share|improve this answer


























      • This is cool, and it returns HW name. On my system $powershell is undefined though, I launch those commands with powershell -c from command prompt. On PS command line 1st one-liner runs as well.

        – SΛLVΘ
        Nov 22 '15 at 19:34






      • 1





        @ThomasWeller which in fact is a name of your network adapter as you per your question. But let me check, logical name should be obtainable as well

        – wmz
        Nov 23 '15 at 21:27






      • 2





        It's on another table @wmz. PS rocks though: powershell "$ip = '192.168.2.4';foreach($int in (gwmi Win32_NetworkAdapter)) {gwmi Win32_NetworkAdapterConfiguration -Filter """Index = $($int.index)""" | ? {$_.IPAddress -contains $ip} | % {$int.NetConnectionID} }"

        – SΛLVΘ
        Nov 23 '15 at 23:00








      • 1





        @ThomasWeller Check my edit. That was tougher than I thought! Fortunately PS supports GetRelated which eases Associators of methods a bit.

        – wmz
        Nov 23 '15 at 23:08






      • 1





        @SalvoF Yup I found it

        – wmz
        Nov 23 '15 at 23:12














      6












      6








      6







      You could use this PS one liner:



      $addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}


      To use it directly from command line:



      powershell "$addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}"


      or if you want to reuse it put it in a script and make the address a parameter



      Edit: to get a name as it shows in Win/Ipconfig:



      $addr='192.168.2.4'; 
      $netconf = get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr};
      $netconf |% {$_.GetRelated("win32_NetworkAdapter")} | select NetConnectionID |%{$_.NetConnectionID}


      (the assignment to intermediary variables is only to make it a bit more readable)






      share|improve this answer















      You could use this PS one liner:



      $addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}


      To use it directly from command line:



      powershell "$addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description}"


      or if you want to reuse it put it in a script and make the address a parameter



      Edit: to get a name as it shows in Win/Ipconfig:



      $addr='192.168.2.4'; 
      $netconf = get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr};
      $netconf |% {$_.GetRelated("win32_NetworkAdapter")} | select NetConnectionID |%{$_.NetConnectionID}


      (the assignment to intermediary variables is only to make it a bit more readable)







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 23 '15 at 23:03

























      answered Nov 22 '15 at 14:51









      wmzwmz

      5,76211127




      5,76211127













      • This is cool, and it returns HW name. On my system $powershell is undefined though, I launch those commands with powershell -c from command prompt. On PS command line 1st one-liner runs as well.

        – SΛLVΘ
        Nov 22 '15 at 19:34






      • 1





        @ThomasWeller which in fact is a name of your network adapter as you per your question. But let me check, logical name should be obtainable as well

        – wmz
        Nov 23 '15 at 21:27






      • 2





        It's on another table @wmz. PS rocks though: powershell "$ip = '192.168.2.4';foreach($int in (gwmi Win32_NetworkAdapter)) {gwmi Win32_NetworkAdapterConfiguration -Filter """Index = $($int.index)""" | ? {$_.IPAddress -contains $ip} | % {$int.NetConnectionID} }"

        – SΛLVΘ
        Nov 23 '15 at 23:00








      • 1





        @ThomasWeller Check my edit. That was tougher than I thought! Fortunately PS supports GetRelated which eases Associators of methods a bit.

        – wmz
        Nov 23 '15 at 23:08






      • 1





        @SalvoF Yup I found it

        – wmz
        Nov 23 '15 at 23:12



















      • This is cool, and it returns HW name. On my system $powershell is undefined though, I launch those commands with powershell -c from command prompt. On PS command line 1st one-liner runs as well.

        – SΛLVΘ
        Nov 22 '15 at 19:34






      • 1





        @ThomasWeller which in fact is a name of your network adapter as you per your question. But let me check, logical name should be obtainable as well

        – wmz
        Nov 23 '15 at 21:27






      • 2





        It's on another table @wmz. PS rocks though: powershell "$ip = '192.168.2.4';foreach($int in (gwmi Win32_NetworkAdapter)) {gwmi Win32_NetworkAdapterConfiguration -Filter """Index = $($int.index)""" | ? {$_.IPAddress -contains $ip} | % {$int.NetConnectionID} }"

        – SΛLVΘ
        Nov 23 '15 at 23:00








      • 1





        @ThomasWeller Check my edit. That was tougher than I thought! Fortunately PS supports GetRelated which eases Associators of methods a bit.

        – wmz
        Nov 23 '15 at 23:08






      • 1





        @SalvoF Yup I found it

        – wmz
        Nov 23 '15 at 23:12

















      This is cool, and it returns HW name. On my system $powershell is undefined though, I launch those commands with powershell -c from command prompt. On PS command line 1st one-liner runs as well.

      – SΛLVΘ
      Nov 22 '15 at 19:34





      This is cool, and it returns HW name. On my system $powershell is undefined though, I launch those commands with powershell -c from command prompt. On PS command line 1st one-liner runs as well.

      – SΛLVΘ
      Nov 22 '15 at 19:34




      1




      1





      @ThomasWeller which in fact is a name of your network adapter as you per your question. But let me check, logical name should be obtainable as well

      – wmz
      Nov 23 '15 at 21:27





      @ThomasWeller which in fact is a name of your network adapter as you per your question. But let me check, logical name should be obtainable as well

      – wmz
      Nov 23 '15 at 21:27




      2




      2





      It's on another table @wmz. PS rocks though: powershell "$ip = '192.168.2.4';foreach($int in (gwmi Win32_NetworkAdapter)) {gwmi Win32_NetworkAdapterConfiguration -Filter """Index = $($int.index)""" | ? {$_.IPAddress -contains $ip} | % {$int.NetConnectionID} }"

      – SΛLVΘ
      Nov 23 '15 at 23:00







      It's on another table @wmz. PS rocks though: powershell "$ip = '192.168.2.4';foreach($int in (gwmi Win32_NetworkAdapter)) {gwmi Win32_NetworkAdapterConfiguration -Filter """Index = $($int.index)""" | ? {$_.IPAddress -contains $ip} | % {$int.NetConnectionID} }"

      – SΛLVΘ
      Nov 23 '15 at 23:00






      1




      1





      @ThomasWeller Check my edit. That was tougher than I thought! Fortunately PS supports GetRelated which eases Associators of methods a bit.

      – wmz
      Nov 23 '15 at 23:08





      @ThomasWeller Check my edit. That was tougher than I thought! Fortunately PS supports GetRelated which eases Associators of methods a bit.

      – wmz
      Nov 23 '15 at 23:08




      1




      1





      @SalvoF Yup I found it

      – wmz
      Nov 23 '15 at 23:12





      @SalvoF Yup I found it

      – wmz
      Nov 23 '15 at 23:12











      4















      I'm looking for a reverse command that displays the name of the
      network adapter for a given IP address.




      Based on everything I tried, this should work seems you say you need to get this information ONLY from the IP address which you already specify in your example.



      INTERACTIVE PROMPT FOR IP ADDRESS TO GET NETWORK CONNECTION NAME



      (Use WMIC and some batch FOR loop token and delim parsing to get the network connection name for a specified IP address.)



      (The result value will echo to a command window and a message box window. It's all batch script but dynamically builds some VBS script functions to simplify the process for anyone that needs.)



      @ECHO ON

      :SetTempFiles
      SET tmpIPaddr=%tmp%~tmpipaddress.vbs
      SET tmpNetConName1=%tmp%~tmpNetConName1.txt
      SET tmpNetConName2=%tmp%~tmpNetConName2.txt
      SET tmpBatFile=%tmp%~tmpBatch.cmd
      SET tmpVBNetCon=%tmp%~tmpVBNetCon.vbs

      IF EXIST "%tmpIPaddr%" DEL /F /Q "%tmpIPaddr%"
      IF EXIST "%tmpNetConName1%" DEL /Q /F "%tmpNetConName1%"
      IF EXIST "%tmpNetConName2%" DEL /Q /F "%tmpNetConName2%"
      IF EXIST "%tmpBatFile%" DEL /Q /F "%tmpBatFile%"
      IF EXIST "%tmpVBNetCon%" DEL /Q /F "%tmpVBNetCon%"

      :InputBox
      SET msgboxTitle=IP ADDRESS
      SET msgboxLine1=Enter the IP address to get its Windows connection name
      >"%tmpIPaddr%" ECHO wsh.echo inputbox("%msgboxLine1%","%msgboxTitle%")
      FOR /F "tokens=*" %%N IN ('cscript //nologo "%tmpIPaddr%"') DO CALL :setvariables %%N
      GOTO EOF

      :setvariables
      SET IPAddress=%~1
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%A IN (`"WMIC NICCONFIG GET IPADDRESS,MACADDRESS /FORMAT:CSV | FIND /I "%IPAddress%""`) DO (SET MACAddress=%%~A)
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%B IN (`"WMIC NIC GET MACADDRESS,NETCONNECTIONID /FORMAT:CSV | FIND /I "%MACAddress%""`) DO ECHO(%%~B>>"%tmpNetConName1%"

      ::: Parse Empty Lines
      FINDSTR "." "%tmpNetConName1%">"%tmpNetConName2%"

      ::: Build Dynamic Batch with ECHO'd Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO ECHO ECHO %%~C>>"%tmpBatFile%"
      IF NOT EXIST "%tmpBatFile%" GOTO :NullExit
      START "" "%tmpBatFile%"

      ::: Build Dynamic VBS with Message Box Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO (SET vbNetconName=%%~C)
      ECHO msgbox "%vbNetconName%",0,"%vbNetconName%">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B

      :NullExit
      ECHO msgbox "Cannot find MAC Address, check to confirm IP Address was correct.",0,"Invalid IP">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B




      ALL ONE-LINERS



      NATIVE WINDOWS ONLY WITH NETSH ALL INTERFACES (ALL IPv4 ADDRESSES)



      NETSH INT IP SHOW CONFIG | FINDSTR /R "Configuration for interface.* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here



      NATIVE WINDOWS ONLY WITH IPCONFIG ALL INTERFACES (ALL IPv4 ADDRESSES)



      IPCONFIG | FINDSTR /R "Ethernet* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here





      USING PCRE2GREP (per @SalvoF)



      SINGLE IP ADDRESS SPECIFIED



      netsh interface ipv4 show address | pcre2grep -B2 "192.168.2.4" | FIND /V "DHCP"


      FIND ALL IP ADDRESSES



      netsh interface ip show config | pcre2grep -B2 ^(?:[0-9]{1,3}.){3}[0-9]{1,3}$ | FIND /V "DHCP" | FIND /V "Gate" | FIND /V "Metric" | FIND /V "Subnet"


      FIND ALL IP ADDRESSES (Cleaned Up Regex (per @SalvoF))



      netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}"


      Please note that the pcre2grep I tried is per @SalvoF [+1] as he suggested but using the.... FIND /V to remove the line above containing DHCP seems to get the desired output as you described. I used NETSH rather than IPCONFIG as well.






      share|improve this answer


























      • This catches some extra information on my machines (as network masks, and such). My point was that in case you have multiple IP addresses, you cease having a "fixed" rule to get to interface name. Initial Q is: given an IP no. how do I find the interface it belongs to? I wasn't looking for all IP's.

        – SΛLVΘ
        Nov 22 '15 at 3:32








      • 1





        Thank you for your inputs! BTW, I noticed that leading and trailing lines on my side were due to language issues. To circumvent those, what do you think about this? netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}" (I cleaned the regex a bit). I'm learning a lot around this place!

        – SΛLVΘ
        Nov 22 '15 at 5:18











      • +1 Thanks for the suggestion. It still has too much output for my usage.

        – Thomas Weller
        Nov 23 '15 at 19:39
















      4















      I'm looking for a reverse command that displays the name of the
      network adapter for a given IP address.




      Based on everything I tried, this should work seems you say you need to get this information ONLY from the IP address which you already specify in your example.



      INTERACTIVE PROMPT FOR IP ADDRESS TO GET NETWORK CONNECTION NAME



      (Use WMIC and some batch FOR loop token and delim parsing to get the network connection name for a specified IP address.)



      (The result value will echo to a command window and a message box window. It's all batch script but dynamically builds some VBS script functions to simplify the process for anyone that needs.)



      @ECHO ON

      :SetTempFiles
      SET tmpIPaddr=%tmp%~tmpipaddress.vbs
      SET tmpNetConName1=%tmp%~tmpNetConName1.txt
      SET tmpNetConName2=%tmp%~tmpNetConName2.txt
      SET tmpBatFile=%tmp%~tmpBatch.cmd
      SET tmpVBNetCon=%tmp%~tmpVBNetCon.vbs

      IF EXIST "%tmpIPaddr%" DEL /F /Q "%tmpIPaddr%"
      IF EXIST "%tmpNetConName1%" DEL /Q /F "%tmpNetConName1%"
      IF EXIST "%tmpNetConName2%" DEL /Q /F "%tmpNetConName2%"
      IF EXIST "%tmpBatFile%" DEL /Q /F "%tmpBatFile%"
      IF EXIST "%tmpVBNetCon%" DEL /Q /F "%tmpVBNetCon%"

      :InputBox
      SET msgboxTitle=IP ADDRESS
      SET msgboxLine1=Enter the IP address to get its Windows connection name
      >"%tmpIPaddr%" ECHO wsh.echo inputbox("%msgboxLine1%","%msgboxTitle%")
      FOR /F "tokens=*" %%N IN ('cscript //nologo "%tmpIPaddr%"') DO CALL :setvariables %%N
      GOTO EOF

      :setvariables
      SET IPAddress=%~1
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%A IN (`"WMIC NICCONFIG GET IPADDRESS,MACADDRESS /FORMAT:CSV | FIND /I "%IPAddress%""`) DO (SET MACAddress=%%~A)
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%B IN (`"WMIC NIC GET MACADDRESS,NETCONNECTIONID /FORMAT:CSV | FIND /I "%MACAddress%""`) DO ECHO(%%~B>>"%tmpNetConName1%"

      ::: Parse Empty Lines
      FINDSTR "." "%tmpNetConName1%">"%tmpNetConName2%"

      ::: Build Dynamic Batch with ECHO'd Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO ECHO ECHO %%~C>>"%tmpBatFile%"
      IF NOT EXIST "%tmpBatFile%" GOTO :NullExit
      START "" "%tmpBatFile%"

      ::: Build Dynamic VBS with Message Box Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO (SET vbNetconName=%%~C)
      ECHO msgbox "%vbNetconName%",0,"%vbNetconName%">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B

      :NullExit
      ECHO msgbox "Cannot find MAC Address, check to confirm IP Address was correct.",0,"Invalid IP">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B




      ALL ONE-LINERS



      NATIVE WINDOWS ONLY WITH NETSH ALL INTERFACES (ALL IPv4 ADDRESSES)



      NETSH INT IP SHOW CONFIG | FINDSTR /R "Configuration for interface.* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here



      NATIVE WINDOWS ONLY WITH IPCONFIG ALL INTERFACES (ALL IPv4 ADDRESSES)



      IPCONFIG | FINDSTR /R "Ethernet* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here





      USING PCRE2GREP (per @SalvoF)



      SINGLE IP ADDRESS SPECIFIED



      netsh interface ipv4 show address | pcre2grep -B2 "192.168.2.4" | FIND /V "DHCP"


      FIND ALL IP ADDRESSES



      netsh interface ip show config | pcre2grep -B2 ^(?:[0-9]{1,3}.){3}[0-9]{1,3}$ | FIND /V "DHCP" | FIND /V "Gate" | FIND /V "Metric" | FIND /V "Subnet"


      FIND ALL IP ADDRESSES (Cleaned Up Regex (per @SalvoF))



      netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}"


      Please note that the pcre2grep I tried is per @SalvoF [+1] as he suggested but using the.... FIND /V to remove the line above containing DHCP seems to get the desired output as you described. I used NETSH rather than IPCONFIG as well.






      share|improve this answer


























      • This catches some extra information on my machines (as network masks, and such). My point was that in case you have multiple IP addresses, you cease having a "fixed" rule to get to interface name. Initial Q is: given an IP no. how do I find the interface it belongs to? I wasn't looking for all IP's.

        – SΛLVΘ
        Nov 22 '15 at 3:32








      • 1





        Thank you for your inputs! BTW, I noticed that leading and trailing lines on my side were due to language issues. To circumvent those, what do you think about this? netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}" (I cleaned the regex a bit). I'm learning a lot around this place!

        – SΛLVΘ
        Nov 22 '15 at 5:18











      • +1 Thanks for the suggestion. It still has too much output for my usage.

        – Thomas Weller
        Nov 23 '15 at 19:39














      4












      4








      4








      I'm looking for a reverse command that displays the name of the
      network adapter for a given IP address.




      Based on everything I tried, this should work seems you say you need to get this information ONLY from the IP address which you already specify in your example.



      INTERACTIVE PROMPT FOR IP ADDRESS TO GET NETWORK CONNECTION NAME



      (Use WMIC and some batch FOR loop token and delim parsing to get the network connection name for a specified IP address.)



      (The result value will echo to a command window and a message box window. It's all batch script but dynamically builds some VBS script functions to simplify the process for anyone that needs.)



      @ECHO ON

      :SetTempFiles
      SET tmpIPaddr=%tmp%~tmpipaddress.vbs
      SET tmpNetConName1=%tmp%~tmpNetConName1.txt
      SET tmpNetConName2=%tmp%~tmpNetConName2.txt
      SET tmpBatFile=%tmp%~tmpBatch.cmd
      SET tmpVBNetCon=%tmp%~tmpVBNetCon.vbs

      IF EXIST "%tmpIPaddr%" DEL /F /Q "%tmpIPaddr%"
      IF EXIST "%tmpNetConName1%" DEL /Q /F "%tmpNetConName1%"
      IF EXIST "%tmpNetConName2%" DEL /Q /F "%tmpNetConName2%"
      IF EXIST "%tmpBatFile%" DEL /Q /F "%tmpBatFile%"
      IF EXIST "%tmpVBNetCon%" DEL /Q /F "%tmpVBNetCon%"

      :InputBox
      SET msgboxTitle=IP ADDRESS
      SET msgboxLine1=Enter the IP address to get its Windows connection name
      >"%tmpIPaddr%" ECHO wsh.echo inputbox("%msgboxLine1%","%msgboxTitle%")
      FOR /F "tokens=*" %%N IN ('cscript //nologo "%tmpIPaddr%"') DO CALL :setvariables %%N
      GOTO EOF

      :setvariables
      SET IPAddress=%~1
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%A IN (`"WMIC NICCONFIG GET IPADDRESS,MACADDRESS /FORMAT:CSV | FIND /I "%IPAddress%""`) DO (SET MACAddress=%%~A)
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%B IN (`"WMIC NIC GET MACADDRESS,NETCONNECTIONID /FORMAT:CSV | FIND /I "%MACAddress%""`) DO ECHO(%%~B>>"%tmpNetConName1%"

      ::: Parse Empty Lines
      FINDSTR "." "%tmpNetConName1%">"%tmpNetConName2%"

      ::: Build Dynamic Batch with ECHO'd Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO ECHO ECHO %%~C>>"%tmpBatFile%"
      IF NOT EXIST "%tmpBatFile%" GOTO :NullExit
      START "" "%tmpBatFile%"

      ::: Build Dynamic VBS with Message Box Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO (SET vbNetconName=%%~C)
      ECHO msgbox "%vbNetconName%",0,"%vbNetconName%">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B

      :NullExit
      ECHO msgbox "Cannot find MAC Address, check to confirm IP Address was correct.",0,"Invalid IP">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B




      ALL ONE-LINERS



      NATIVE WINDOWS ONLY WITH NETSH ALL INTERFACES (ALL IPv4 ADDRESSES)



      NETSH INT IP SHOW CONFIG | FINDSTR /R "Configuration for interface.* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here



      NATIVE WINDOWS ONLY WITH IPCONFIG ALL INTERFACES (ALL IPv4 ADDRESSES)



      IPCONFIG | FINDSTR /R "Ethernet* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here





      USING PCRE2GREP (per @SalvoF)



      SINGLE IP ADDRESS SPECIFIED



      netsh interface ipv4 show address | pcre2grep -B2 "192.168.2.4" | FIND /V "DHCP"


      FIND ALL IP ADDRESSES



      netsh interface ip show config | pcre2grep -B2 ^(?:[0-9]{1,3}.){3}[0-9]{1,3}$ | FIND /V "DHCP" | FIND /V "Gate" | FIND /V "Metric" | FIND /V "Subnet"


      FIND ALL IP ADDRESSES (Cleaned Up Regex (per @SalvoF))



      netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}"


      Please note that the pcre2grep I tried is per @SalvoF [+1] as he suggested but using the.... FIND /V to remove the line above containing DHCP seems to get the desired output as you described. I used NETSH rather than IPCONFIG as well.






      share|improve this answer
















      I'm looking for a reverse command that displays the name of the
      network adapter for a given IP address.




      Based on everything I tried, this should work seems you say you need to get this information ONLY from the IP address which you already specify in your example.



      INTERACTIVE PROMPT FOR IP ADDRESS TO GET NETWORK CONNECTION NAME



      (Use WMIC and some batch FOR loop token and delim parsing to get the network connection name for a specified IP address.)



      (The result value will echo to a command window and a message box window. It's all batch script but dynamically builds some VBS script functions to simplify the process for anyone that needs.)



      @ECHO ON

      :SetTempFiles
      SET tmpIPaddr=%tmp%~tmpipaddress.vbs
      SET tmpNetConName1=%tmp%~tmpNetConName1.txt
      SET tmpNetConName2=%tmp%~tmpNetConName2.txt
      SET tmpBatFile=%tmp%~tmpBatch.cmd
      SET tmpVBNetCon=%tmp%~tmpVBNetCon.vbs

      IF EXIST "%tmpIPaddr%" DEL /F /Q "%tmpIPaddr%"
      IF EXIST "%tmpNetConName1%" DEL /Q /F "%tmpNetConName1%"
      IF EXIST "%tmpNetConName2%" DEL /Q /F "%tmpNetConName2%"
      IF EXIST "%tmpBatFile%" DEL /Q /F "%tmpBatFile%"
      IF EXIST "%tmpVBNetCon%" DEL /Q /F "%tmpVBNetCon%"

      :InputBox
      SET msgboxTitle=IP ADDRESS
      SET msgboxLine1=Enter the IP address to get its Windows connection name
      >"%tmpIPaddr%" ECHO wsh.echo inputbox("%msgboxLine1%","%msgboxTitle%")
      FOR /F "tokens=*" %%N IN ('cscript //nologo "%tmpIPaddr%"') DO CALL :setvariables %%N
      GOTO EOF

      :setvariables
      SET IPAddress=%~1
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%A IN (`"WMIC NICCONFIG GET IPADDRESS,MACADDRESS /FORMAT:CSV | FIND /I "%IPAddress%""`) DO (SET MACAddress=%%~A)
      FOR /F "USEBACKQ TOKENS=3 DELIMS=," %%B IN (`"WMIC NIC GET MACADDRESS,NETCONNECTIONID /FORMAT:CSV | FIND /I "%MACAddress%""`) DO ECHO(%%~B>>"%tmpNetConName1%"

      ::: Parse Empty Lines
      FINDSTR "." "%tmpNetConName1%">"%tmpNetConName2%"

      ::: Build Dynamic Batch with ECHO'd Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO ECHO ECHO %%~C>>"%tmpBatFile%"
      IF NOT EXIST "%tmpBatFile%" GOTO :NullExit
      START "" "%tmpBatFile%"

      ::: Build Dynamic VBS with Message Box Network Connection Value
      FOR /F "tokens=*" %%C IN (%tmpNetConName2%) DO (SET vbNetconName=%%~C)
      ECHO msgbox "%vbNetconName%",0,"%vbNetconName%">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B

      :NullExit
      ECHO msgbox "Cannot find MAC Address, check to confirm IP Address was correct.",0,"Invalid IP">"%tmpVBNetCon%"
      START /B "" "%tmpVBNetCon%"
      EXIT /B




      ALL ONE-LINERS



      NATIVE WINDOWS ONLY WITH NETSH ALL INTERFACES (ALL IPv4 ADDRESSES)



      NETSH INT IP SHOW CONFIG | FINDSTR /R "Configuration for interface.* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here



      NATIVE WINDOWS ONLY WITH IPCONFIG ALL INTERFACES (ALL IPv4 ADDRESSES)



      IPCONFIG | FINDSTR /R "Ethernet* Address.*[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*"


      enter image description here





      USING PCRE2GREP (per @SalvoF)



      SINGLE IP ADDRESS SPECIFIED



      netsh interface ipv4 show address | pcre2grep -B2 "192.168.2.4" | FIND /V "DHCP"


      FIND ALL IP ADDRESSES



      netsh interface ip show config | pcre2grep -B2 ^(?:[0-9]{1,3}.){3}[0-9]{1,3}$ | FIND /V "DHCP" | FIND /V "Gate" | FIND /V "Metric" | FIND /V "Subnet"


      FIND ALL IP ADDRESSES (Cleaned Up Regex (per @SalvoF))



      netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}"


      Please note that the pcre2grep I tried is per @SalvoF [+1] as he suggested but using the.... FIND /V to remove the line above containing DHCP seems to get the desired output as you described. I used NETSH rather than IPCONFIG as well.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 7 '15 at 12:56

























      answered Nov 22 '15 at 2:58









      Pimp Juice ITPimp Juice IT

      25k114177




      25k114177













      • This catches some extra information on my machines (as network masks, and such). My point was that in case you have multiple IP addresses, you cease having a "fixed" rule to get to interface name. Initial Q is: given an IP no. how do I find the interface it belongs to? I wasn't looking for all IP's.

        – SΛLVΘ
        Nov 22 '15 at 3:32








      • 1





        Thank you for your inputs! BTW, I noticed that leading and trailing lines on my side were due to language issues. To circumvent those, what do you think about this? netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}" (I cleaned the regex a bit). I'm learning a lot around this place!

        – SΛLVΘ
        Nov 22 '15 at 5:18











      • +1 Thanks for the suggestion. It still has too much output for my usage.

        – Thomas Weller
        Nov 23 '15 at 19:39



















      • This catches some extra information on my machines (as network masks, and such). My point was that in case you have multiple IP addresses, you cease having a "fixed" rule to get to interface name. Initial Q is: given an IP no. how do I find the interface it belongs to? I wasn't looking for all IP's.

        – SΛLVΘ
        Nov 22 '15 at 3:32








      • 1





        Thank you for your inputs! BTW, I noticed that leading and trailing lines on my side were due to language issues. To circumvent those, what do you think about this? netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}" (I cleaned the regex a bit). I'm learning a lot around this place!

        – SΛLVΘ
        Nov 22 '15 at 5:18











      • +1 Thanks for the suggestion. It still has too much output for my usage.

        – Thomas Weller
        Nov 23 '15 at 19:39

















      This catches some extra information on my machines (as network masks, and such). My point was that in case you have multiple IP addresses, you cease having a "fixed" rule to get to interface name. Initial Q is: given an IP no. how do I find the interface it belongs to? I wasn't looking for all IP's.

      – SΛLVΘ
      Nov 22 '15 at 3:32







      This catches some extra information on my machines (as network masks, and such). My point was that in case you have multiple IP addresses, you cease having a "fixed" rule to get to interface name. Initial Q is: given an IP no. how do I find the interface it belongs to? I wasn't looking for all IP's.

      – SΛLVΘ
      Nov 22 '15 at 3:32






      1




      1





      Thank you for your inputs! BTW, I noticed that leading and trailing lines on my side were due to language issues. To circumvent those, what do you think about this? netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}" (I cleaned the regex a bit). I'm learning a lot around this place!

      – SΛLVΘ
      Nov 22 '15 at 5:18





      Thank you for your inputs! BTW, I noticed that leading and trailing lines on my side were due to language issues. To circumvent those, what do you think about this? netsh interface ip show config | pcre2grep "^[A-Z]|IP.*([0-9]{1,3}(.|)){4}" (I cleaned the regex a bit). I'm learning a lot around this place!

      – SΛLVΘ
      Nov 22 '15 at 5:18













      +1 Thanks for the suggestion. It still has too much output for my usage.

      – Thomas Weller
      Nov 23 '15 at 19:39





      +1 Thanks for the suggestion. It still has too much output for my usage.

      – Thomas Weller
      Nov 23 '15 at 19:39











      3














      To be more accurate, following OP's example, I'd use sed, which can be found under the usrlocalwbin folder of this zipped file (UnxUtils project).



      ipconfig | sed -rn "/^[A-Z]/h;/192.168.2.4/{g;s/.* adapter (.*):/1/p;}"


      -n suppresses non matching lines; first pattern finds any line starting with capital letter, then h puts it away on hold space; second match is on wanted IP number: at this point, line holding interface name is recalled (g), extra leading text stripped (s), and printed (p).






      share|improve this answer


























      • -B4 almost works, it just leaves me with the prefix "Ethernet adapter", which does not belong to the adapter name + 4 lines of unrelated output. But the message is clear: find a tool that does it :-)

        – Thomas Weller
        Nov 22 '15 at 0:47








      • 1





        Could you update your post to show unfiltered ipconfig output? (Obfuscate or change data for privacy)

        – SΛLVΘ
        Nov 22 '15 at 0:52











      • Ok, added. It also seems to be tricky to handle adapters with multiple addresses.

        – Thomas Weller
        Nov 22 '15 at 0:58






      • 1





        That's brilliant @PJMahoney. What would be the output with multiple IP addresses though? I made an effort for a general solution by using sed; maybe your solution too can be tweaked to reach that goal.

        – SΛLVΘ
        Nov 22 '15 at 3:10











      • The sed one works if I add another | sed -rn "s/^.* adapter (.*):/1/p"

        – Thomas Weller
        Nov 23 '15 at 21:58
















      3














      To be more accurate, following OP's example, I'd use sed, which can be found under the usrlocalwbin folder of this zipped file (UnxUtils project).



      ipconfig | sed -rn "/^[A-Z]/h;/192.168.2.4/{g;s/.* adapter (.*):/1/p;}"


      -n suppresses non matching lines; first pattern finds any line starting with capital letter, then h puts it away on hold space; second match is on wanted IP number: at this point, line holding interface name is recalled (g), extra leading text stripped (s), and printed (p).






      share|improve this answer


























      • -B4 almost works, it just leaves me with the prefix "Ethernet adapter", which does not belong to the adapter name + 4 lines of unrelated output. But the message is clear: find a tool that does it :-)

        – Thomas Weller
        Nov 22 '15 at 0:47








      • 1





        Could you update your post to show unfiltered ipconfig output? (Obfuscate or change data for privacy)

        – SΛLVΘ
        Nov 22 '15 at 0:52











      • Ok, added. It also seems to be tricky to handle adapters with multiple addresses.

        – Thomas Weller
        Nov 22 '15 at 0:58






      • 1





        That's brilliant @PJMahoney. What would be the output with multiple IP addresses though? I made an effort for a general solution by using sed; maybe your solution too can be tweaked to reach that goal.

        – SΛLVΘ
        Nov 22 '15 at 3:10











      • The sed one works if I add another | sed -rn "s/^.* adapter (.*):/1/p"

        – Thomas Weller
        Nov 23 '15 at 21:58














      3












      3








      3







      To be more accurate, following OP's example, I'd use sed, which can be found under the usrlocalwbin folder of this zipped file (UnxUtils project).



      ipconfig | sed -rn "/^[A-Z]/h;/192.168.2.4/{g;s/.* adapter (.*):/1/p;}"


      -n suppresses non matching lines; first pattern finds any line starting with capital letter, then h puts it away on hold space; second match is on wanted IP number: at this point, line holding interface name is recalled (g), extra leading text stripped (s), and printed (p).






      share|improve this answer















      To be more accurate, following OP's example, I'd use sed, which can be found under the usrlocalwbin folder of this zipped file (UnxUtils project).



      ipconfig | sed -rn "/^[A-Z]/h;/192.168.2.4/{g;s/.* adapter (.*):/1/p;}"


      -n suppresses non matching lines; first pattern finds any line starting with capital letter, then h puts it away on hold space; second match is on wanted IP number: at this point, line holding interface name is recalled (g), extra leading text stripped (s), and printed (p).







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 23 '15 at 23:33

























      answered Nov 22 '15 at 0:29









      SΛLVΘSΛLVΘ

      1,0471610




      1,0471610













      • -B4 almost works, it just leaves me with the prefix "Ethernet adapter", which does not belong to the adapter name + 4 lines of unrelated output. But the message is clear: find a tool that does it :-)

        – Thomas Weller
        Nov 22 '15 at 0:47








      • 1





        Could you update your post to show unfiltered ipconfig output? (Obfuscate or change data for privacy)

        – SΛLVΘ
        Nov 22 '15 at 0:52











      • Ok, added. It also seems to be tricky to handle adapters with multiple addresses.

        – Thomas Weller
        Nov 22 '15 at 0:58






      • 1





        That's brilliant @PJMahoney. What would be the output with multiple IP addresses though? I made an effort for a general solution by using sed; maybe your solution too can be tweaked to reach that goal.

        – SΛLVΘ
        Nov 22 '15 at 3:10











      • The sed one works if I add another | sed -rn "s/^.* adapter (.*):/1/p"

        – Thomas Weller
        Nov 23 '15 at 21:58



















      • -B4 almost works, it just leaves me with the prefix "Ethernet adapter", which does not belong to the adapter name + 4 lines of unrelated output. But the message is clear: find a tool that does it :-)

        – Thomas Weller
        Nov 22 '15 at 0:47








      • 1





        Could you update your post to show unfiltered ipconfig output? (Obfuscate or change data for privacy)

        – SΛLVΘ
        Nov 22 '15 at 0:52











      • Ok, added. It also seems to be tricky to handle adapters with multiple addresses.

        – Thomas Weller
        Nov 22 '15 at 0:58






      • 1





        That's brilliant @PJMahoney. What would be the output with multiple IP addresses though? I made an effort for a general solution by using sed; maybe your solution too can be tweaked to reach that goal.

        – SΛLVΘ
        Nov 22 '15 at 3:10











      • The sed one works if I add another | sed -rn "s/^.* adapter (.*):/1/p"

        – Thomas Weller
        Nov 23 '15 at 21:58

















      -B4 almost works, it just leaves me with the prefix "Ethernet adapter", which does not belong to the adapter name + 4 lines of unrelated output. But the message is clear: find a tool that does it :-)

      – Thomas Weller
      Nov 22 '15 at 0:47







      -B4 almost works, it just leaves me with the prefix "Ethernet adapter", which does not belong to the adapter name + 4 lines of unrelated output. But the message is clear: find a tool that does it :-)

      – Thomas Weller
      Nov 22 '15 at 0:47






      1




      1





      Could you update your post to show unfiltered ipconfig output? (Obfuscate or change data for privacy)

      – SΛLVΘ
      Nov 22 '15 at 0:52





      Could you update your post to show unfiltered ipconfig output? (Obfuscate or change data for privacy)

      – SΛLVΘ
      Nov 22 '15 at 0:52













      Ok, added. It also seems to be tricky to handle adapters with multiple addresses.

      – Thomas Weller
      Nov 22 '15 at 0:58





      Ok, added. It also seems to be tricky to handle adapters with multiple addresses.

      – Thomas Weller
      Nov 22 '15 at 0:58




      1




      1





      That's brilliant @PJMahoney. What would be the output with multiple IP addresses though? I made an effort for a general solution by using sed; maybe your solution too can be tweaked to reach that goal.

      – SΛLVΘ
      Nov 22 '15 at 3:10





      That's brilliant @PJMahoney. What would be the output with multiple IP addresses though? I made an effort for a general solution by using sed; maybe your solution too can be tweaked to reach that goal.

      – SΛLVΘ
      Nov 22 '15 at 3:10













      The sed one works if I add another | sed -rn "s/^.* adapter (.*):/1/p"

      – Thomas Weller
      Nov 23 '15 at 21:58





      The sed one works if I add another | sed -rn "s/^.* adapter (.*):/1/p"

      – Thomas Weller
      Nov 23 '15 at 21:58











      2














      Just for the record, here's another batch solution, it exploits delayed expansion of the %ERRORLEVEL% system variable:



      @echo off
      setlocal EnableDelayedExpansion
      for /f "delims=" %%L in ('ipconfig') do (
      echo %%L | findstr /r "^[A-Z]" 1>NUL
      if !errorlevel! == 0 set "_int=%%L"
      echo %%L | findstr /c:%1 1>NUL
      if !errorlevel! == 0 (
      set "_int=!_int::=!"
      echo !_int:* adapter =!
      goto:eof
      )
      )


      It can be invoked this way: find_int.cmd 192.168.1.100






      share|improve this answer


























      • Hehe. That is a neat pure batch solution. Well done ;)

        – DavidPostill
        Nov 23 '15 at 9:40











      • +1 The output is very close to what I need. Thanks

        – Thomas Weller
        Nov 23 '15 at 19:44











      • I edited the sed one-liner, leaving interface name as sole output. Of course, you can write a simple batch file for that too, passing the IP no. as argument (%1).

        – SΛLVΘ
        Nov 23 '15 at 20:19













      • @ThomasWeller, tuned this one too. Cheers!

        – SΛLVΘ
        Nov 23 '15 at 23:48
















      2














      Just for the record, here's another batch solution, it exploits delayed expansion of the %ERRORLEVEL% system variable:



      @echo off
      setlocal EnableDelayedExpansion
      for /f "delims=" %%L in ('ipconfig') do (
      echo %%L | findstr /r "^[A-Z]" 1>NUL
      if !errorlevel! == 0 set "_int=%%L"
      echo %%L | findstr /c:%1 1>NUL
      if !errorlevel! == 0 (
      set "_int=!_int::=!"
      echo !_int:* adapter =!
      goto:eof
      )
      )


      It can be invoked this way: find_int.cmd 192.168.1.100






      share|improve this answer


























      • Hehe. That is a neat pure batch solution. Well done ;)

        – DavidPostill
        Nov 23 '15 at 9:40











      • +1 The output is very close to what I need. Thanks

        – Thomas Weller
        Nov 23 '15 at 19:44











      • I edited the sed one-liner, leaving interface name as sole output. Of course, you can write a simple batch file for that too, passing the IP no. as argument (%1).

        – SΛLVΘ
        Nov 23 '15 at 20:19













      • @ThomasWeller, tuned this one too. Cheers!

        – SΛLVΘ
        Nov 23 '15 at 23:48














      2












      2








      2







      Just for the record, here's another batch solution, it exploits delayed expansion of the %ERRORLEVEL% system variable:



      @echo off
      setlocal EnableDelayedExpansion
      for /f "delims=" %%L in ('ipconfig') do (
      echo %%L | findstr /r "^[A-Z]" 1>NUL
      if !errorlevel! == 0 set "_int=%%L"
      echo %%L | findstr /c:%1 1>NUL
      if !errorlevel! == 0 (
      set "_int=!_int::=!"
      echo !_int:* adapter =!
      goto:eof
      )
      )


      It can be invoked this way: find_int.cmd 192.168.1.100






      share|improve this answer















      Just for the record, here's another batch solution, it exploits delayed expansion of the %ERRORLEVEL% system variable:



      @echo off
      setlocal EnableDelayedExpansion
      for /f "delims=" %%L in ('ipconfig') do (
      echo %%L | findstr /r "^[A-Z]" 1>NUL
      if !errorlevel! == 0 set "_int=%%L"
      echo %%L | findstr /c:%1 1>NUL
      if !errorlevel! == 0 (
      set "_int=!_int::=!"
      echo !_int:* adapter =!
      goto:eof
      )
      )


      It can be invoked this way: find_int.cmd 192.168.1.100







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 23 '15 at 23:52

























      answered Nov 23 '15 at 9:33









      SΛLVΘSΛLVΘ

      1,0471610




      1,0471610













      • Hehe. That is a neat pure batch solution. Well done ;)

        – DavidPostill
        Nov 23 '15 at 9:40











      • +1 The output is very close to what I need. Thanks

        – Thomas Weller
        Nov 23 '15 at 19:44











      • I edited the sed one-liner, leaving interface name as sole output. Of course, you can write a simple batch file for that too, passing the IP no. as argument (%1).

        – SΛLVΘ
        Nov 23 '15 at 20:19













      • @ThomasWeller, tuned this one too. Cheers!

        – SΛLVΘ
        Nov 23 '15 at 23:48



















      • Hehe. That is a neat pure batch solution. Well done ;)

        – DavidPostill
        Nov 23 '15 at 9:40











      • +1 The output is very close to what I need. Thanks

        – Thomas Weller
        Nov 23 '15 at 19:44











      • I edited the sed one-liner, leaving interface name as sole output. Of course, you can write a simple batch file for that too, passing the IP no. as argument (%1).

        – SΛLVΘ
        Nov 23 '15 at 20:19













      • @ThomasWeller, tuned this one too. Cheers!

        – SΛLVΘ
        Nov 23 '15 at 23:48

















      Hehe. That is a neat pure batch solution. Well done ;)

      – DavidPostill
      Nov 23 '15 at 9:40





      Hehe. That is a neat pure batch solution. Well done ;)

      – DavidPostill
      Nov 23 '15 at 9:40













      +1 The output is very close to what I need. Thanks

      – Thomas Weller
      Nov 23 '15 at 19:44





      +1 The output is very close to what I need. Thanks

      – Thomas Weller
      Nov 23 '15 at 19:44













      I edited the sed one-liner, leaving interface name as sole output. Of course, you can write a simple batch file for that too, passing the IP no. as argument (%1).

      – SΛLVΘ
      Nov 23 '15 at 20:19







      I edited the sed one-liner, leaving interface name as sole output. Of course, you can write a simple batch file for that too, passing the IP no. as argument (%1).

      – SΛLVΘ
      Nov 23 '15 at 20:19















      @ThomasWeller, tuned this one too. Cheers!

      – SΛLVΘ
      Nov 23 '15 at 23:48





      @ThomasWeller, tuned this one too. Cheers!

      – SΛLVΘ
      Nov 23 '15 at 23:48











      1














      Thanks for the effort everyone. It seems there are several hurdles:




      • the number of IP addresses assigned to an adapter

      • the language of the OS


      All the -Bx and Regex stuff seems to break easily, so I googled for something I could implement myself and came up with the following C# program, which takes the IP address as parameter (IP2Adapter <IP>):



      using System;
      using System.Net.NetworkInformation;
      using System.Net.Sockets;

      namespace IP2Adapter
      {
      class Program
      {
      static void Main(string[] args)
      {
      var adapters = NetworkInterface.GetAllNetworkInterfaces();
      foreach (var adapter in adapters)
      {
      var ipProps = adapter.GetIPProperties();
      foreach (var ip in ipProps.UnicastAddresses)
      {
      if ((adapter.OperationalStatus == OperationalStatus.Up)
      && (ip.Address.AddressFamily == AddressFamily.InterNetwork))
      {
      if (ip.Address.ToString() == args[0])
      Console.Out.WriteLine(adapter.Name);
      }
      }
      }
      }
      }
      }





      share|improve this answer




























        1














        Thanks for the effort everyone. It seems there are several hurdles:




        • the number of IP addresses assigned to an adapter

        • the language of the OS


        All the -Bx and Regex stuff seems to break easily, so I googled for something I could implement myself and came up with the following C# program, which takes the IP address as parameter (IP2Adapter <IP>):



        using System;
        using System.Net.NetworkInformation;
        using System.Net.Sockets;

        namespace IP2Adapter
        {
        class Program
        {
        static void Main(string[] args)
        {
        var adapters = NetworkInterface.GetAllNetworkInterfaces();
        foreach (var adapter in adapters)
        {
        var ipProps = adapter.GetIPProperties();
        foreach (var ip in ipProps.UnicastAddresses)
        {
        if ((adapter.OperationalStatus == OperationalStatus.Up)
        && (ip.Address.AddressFamily == AddressFamily.InterNetwork))
        {
        if (ip.Address.ToString() == args[0])
        Console.Out.WriteLine(adapter.Name);
        }
        }
        }
        }
        }
        }





        share|improve this answer


























          1












          1








          1







          Thanks for the effort everyone. It seems there are several hurdles:




          • the number of IP addresses assigned to an adapter

          • the language of the OS


          All the -Bx and Regex stuff seems to break easily, so I googled for something I could implement myself and came up with the following C# program, which takes the IP address as parameter (IP2Adapter <IP>):



          using System;
          using System.Net.NetworkInformation;
          using System.Net.Sockets;

          namespace IP2Adapter
          {
          class Program
          {
          static void Main(string[] args)
          {
          var adapters = NetworkInterface.GetAllNetworkInterfaces();
          foreach (var adapter in adapters)
          {
          var ipProps = adapter.GetIPProperties();
          foreach (var ip in ipProps.UnicastAddresses)
          {
          if ((adapter.OperationalStatus == OperationalStatus.Up)
          && (ip.Address.AddressFamily == AddressFamily.InterNetwork))
          {
          if (ip.Address.ToString() == args[0])
          Console.Out.WriteLine(adapter.Name);
          }
          }
          }
          }
          }
          }





          share|improve this answer













          Thanks for the effort everyone. It seems there are several hurdles:




          • the number of IP addresses assigned to an adapter

          • the language of the OS


          All the -Bx and Regex stuff seems to break easily, so I googled for something I could implement myself and came up with the following C# program, which takes the IP address as parameter (IP2Adapter <IP>):



          using System;
          using System.Net.NetworkInformation;
          using System.Net.Sockets;

          namespace IP2Adapter
          {
          class Program
          {
          static void Main(string[] args)
          {
          var adapters = NetworkInterface.GetAllNetworkInterfaces();
          foreach (var adapter in adapters)
          {
          var ipProps = adapter.GetIPProperties();
          foreach (var ip in ipProps.UnicastAddresses)
          {
          if ((adapter.OperationalStatus == OperationalStatus.Up)
          && (ip.Address.AddressFamily == AddressFamily.InterNetwork))
          {
          if (ip.Address.ToString() == args[0])
          Console.Out.WriteLine(adapter.Name);
          }
          }
          }
          }
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '15 at 19:42









          Thomas WellerThomas Weller

          3,06563163




          3,06563163























              0














              On Windows 10 Powershell, this can be achieved with the following:



              Get-NetIPAddress -IPAddress '192.168.2.4' | select InterfaceAlias | %{$_.InterfaceAlias};


              This will give a result such as Wi-Fi.



              Where You can substitute InterfaceAlias for any other object property.



              To get all properties, simply omit the pipes, and run: Get-NetIPAddress -IPAddress '192.168.2.4'.



              Other network adapter related properties (such as Description) can usually be queried based on InterfaceAlias or InterfaceIndex, eg.:



              Get-NetAdapter -InterfaceAlias Wi-Fi | select InterfaceDescription | %{$_.InterfaceDescription};


              Which will give something like: Intel(R) Dual Band Wireless-AC 8265.



              Read more on the docs: https://docs.microsoft.com/en-us/powershell/module/nettcpip/get-netipaddress?view=win10-ps






              share|improve this answer










              New contributor




              MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                0














                On Windows 10 Powershell, this can be achieved with the following:



                Get-NetIPAddress -IPAddress '192.168.2.4' | select InterfaceAlias | %{$_.InterfaceAlias};


                This will give a result such as Wi-Fi.



                Where You can substitute InterfaceAlias for any other object property.



                To get all properties, simply omit the pipes, and run: Get-NetIPAddress -IPAddress '192.168.2.4'.



                Other network adapter related properties (such as Description) can usually be queried based on InterfaceAlias or InterfaceIndex, eg.:



                Get-NetAdapter -InterfaceAlias Wi-Fi | select InterfaceDescription | %{$_.InterfaceDescription};


                Which will give something like: Intel(R) Dual Band Wireless-AC 8265.



                Read more on the docs: https://docs.microsoft.com/en-us/powershell/module/nettcpip/get-netipaddress?view=win10-ps






                share|improve this answer










                New contributor




                MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  0












                  0








                  0







                  On Windows 10 Powershell, this can be achieved with the following:



                  Get-NetIPAddress -IPAddress '192.168.2.4' | select InterfaceAlias | %{$_.InterfaceAlias};


                  This will give a result such as Wi-Fi.



                  Where You can substitute InterfaceAlias for any other object property.



                  To get all properties, simply omit the pipes, and run: Get-NetIPAddress -IPAddress '192.168.2.4'.



                  Other network adapter related properties (such as Description) can usually be queried based on InterfaceAlias or InterfaceIndex, eg.:



                  Get-NetAdapter -InterfaceAlias Wi-Fi | select InterfaceDescription | %{$_.InterfaceDescription};


                  Which will give something like: Intel(R) Dual Band Wireless-AC 8265.



                  Read more on the docs: https://docs.microsoft.com/en-us/powershell/module/nettcpip/get-netipaddress?view=win10-ps






                  share|improve this answer










                  New contributor




                  MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  On Windows 10 Powershell, this can be achieved with the following:



                  Get-NetIPAddress -IPAddress '192.168.2.4' | select InterfaceAlias | %{$_.InterfaceAlias};


                  This will give a result such as Wi-Fi.



                  Where You can substitute InterfaceAlias for any other object property.



                  To get all properties, simply omit the pipes, and run: Get-NetIPAddress -IPAddress '192.168.2.4'.



                  Other network adapter related properties (such as Description) can usually be queried based on InterfaceAlias or InterfaceIndex, eg.:



                  Get-NetAdapter -InterfaceAlias Wi-Fi | select InterfaceDescription | %{$_.InterfaceDescription};


                  Which will give something like: Intel(R) Dual Band Wireless-AC 8265.



                  Read more on the docs: https://docs.microsoft.com/en-us/powershell/module/nettcpip/get-netipaddress?view=win10-ps







                  share|improve this answer










                  New contributor




                  MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer








                  edited 1 min ago





















                  New contributor




                  MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 12 mins ago









                  MrMeszarosMrMeszaros

                  1013




                  1013




                  New contributor




                  MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  MrMeszaros is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1003746%2fcommand-to-find-network-interface-for-ip%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                      VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

                      Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...