Getting the IP-Address of the machine from batch scrip using “VirtualBox Host-Only”
I want to catch the IP-Address of my machine using a batch file.
I am using the below code:
for /f "delims= tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set IPAddress=%%a
echo IP-Adress is %IPAddress%
I have Virtual Box also installed in my system. So, an Ethernet adapter is also installed for the VB
, with name Ethernet adapter VirtualBox Host-Only Network
.
Now, whenever I am pinging my machine using ComputerName
, I am getting the response from the VB Host-Only Network
adapter.
ping %ComputerName% -4
Pinging CTH-0098 [192.168.56.1] with 32 bytes of data:
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
But my actual system IP-Address is 192.168.0.100
How to catch this IP address?
batch-file virtualbox ip-address
add a comment |
I want to catch the IP-Address of my machine using a batch file.
I am using the below code:
for /f "delims= tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set IPAddress=%%a
echo IP-Adress is %IPAddress%
I have Virtual Box also installed in my system. So, an Ethernet adapter is also installed for the VB
, with name Ethernet adapter VirtualBox Host-Only Network
.
Now, whenever I am pinging my machine using ComputerName
, I am getting the response from the VB Host-Only Network
adapter.
ping %ComputerName% -4
Pinging CTH-0098 [192.168.56.1] with 32 bytes of data:
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
But my actual system IP-Address is 192.168.0.100
How to catch this IP address?
batch-file virtualbox ip-address
Actually your pc has now at least 2 IPv4 addresses, see ipconfig /all.
– LotPings
Nov 22 '18 at 17:08
yes. 1. VirtualBox Host-Only Ethernet Adapter 2. Intel(R) Ethernet Connection I217-LM
– praveen345
Nov 23 '18 at 9:18
add a comment |
I want to catch the IP-Address of my machine using a batch file.
I am using the below code:
for /f "delims= tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set IPAddress=%%a
echo IP-Adress is %IPAddress%
I have Virtual Box also installed in my system. So, an Ethernet adapter is also installed for the VB
, with name Ethernet adapter VirtualBox Host-Only Network
.
Now, whenever I am pinging my machine using ComputerName
, I am getting the response from the VB Host-Only Network
adapter.
ping %ComputerName% -4
Pinging CTH-0098 [192.168.56.1] with 32 bytes of data:
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
But my actual system IP-Address is 192.168.0.100
How to catch this IP address?
batch-file virtualbox ip-address
I want to catch the IP-Address of my machine using a batch file.
I am using the below code:
for /f "delims= tokens=2" %%a in ('ping -4 -n 1 %ComputerName% ^| findstr [') do set IPAddress=%%a
echo IP-Adress is %IPAddress%
I have Virtual Box also installed in my system. So, an Ethernet adapter is also installed for the VB
, with name Ethernet adapter VirtualBox Host-Only Network
.
Now, whenever I am pinging my machine using ComputerName
, I am getting the response from the VB Host-Only Network
adapter.
ping %ComputerName% -4
Pinging CTH-0098 [192.168.56.1] with 32 bytes of data:
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
But my actual system IP-Address is 192.168.0.100
How to catch this IP address?
batch-file virtualbox ip-address
batch-file virtualbox ip-address
edited Nov 22 '18 at 18:14
Federico Grandi
3,23121230
3,23121230
asked Nov 22 '18 at 15:29
praveen345praveen345
1
1
Actually your pc has now at least 2 IPv4 addresses, see ipconfig /all.
– LotPings
Nov 22 '18 at 17:08
yes. 1. VirtualBox Host-Only Ethernet Adapter 2. Intel(R) Ethernet Connection I217-LM
– praveen345
Nov 23 '18 at 9:18
add a comment |
Actually your pc has now at least 2 IPv4 addresses, see ipconfig /all.
– LotPings
Nov 22 '18 at 17:08
yes. 1. VirtualBox Host-Only Ethernet Adapter 2. Intel(R) Ethernet Connection I217-LM
– praveen345
Nov 23 '18 at 9:18
Actually your pc has now at least 2 IPv4 addresses, see ipconfig /all.
– LotPings
Nov 22 '18 at 17:08
Actually your pc has now at least 2 IPv4 addresses, see ipconfig /all.
– LotPings
Nov 22 '18 at 17:08
yes. 1. VirtualBox Host-Only Ethernet Adapter 2. Intel(R) Ethernet Connection I217-LM
– praveen345
Nov 23 '18 at 9:18
yes. 1. VirtualBox Host-Only Ethernet Adapter 2. Intel(R) Ethernet Connection I217-LM
– praveen345
Nov 23 '18 at 9:18
add a comment |
1 Answer
1
active
oldest
votes
if you have more than one interface, ping
is not helpful. The netsh
command gives you far more flexibity:
for /f "delims=" %%a in ('netsh interface ipv4 show addresses name^="Local Area Connection" ^|find "IP"') do for %%b in (%%a) do set "ip=%%b"
echo Your IP is: %ip%
Change Local Area Connection
to your actual interface name (look for the exact name with netsh interface show interface
)
Thanks Stephan. But, I cannot use this as, I will be using the same batch file across several machines. So, I need the solution to be as generic as possible.
– praveen345
Nov 23 '18 at 13:35
netsh
comes with Windows XP with Service Pack 1 (SP1) and later. I surely hope you are not working with even older Windows versions.
– Stephan
Nov 23 '18 at 13:53
Thanks. Sorry for not mentioning my concern clearly. I cannot use netsh because: I will be using this batch file across several machines and for those machines the interface names might not be same.
– praveen345
Nov 26 '18 at 13:42
ok I understand. But if you have several adapters, how to choose the right one then?ping
obviously can't decide correctly. When I'm right, the address you're looking for is one ofnetsh interface ipv4 show config | find "IP"
? Which one?
– Stephan
Nov 26 '18 at 14:24
I want the one with name "Ethernet". However, I can use the batch file as long as there is no change in the network adapter or network adapter name And if there is any change in the N/W adapter name I need to update the batch file. Although the chance of changing adapter name is less, the chance of using the adapter to "Wi-Fi" is there. Is there any other alternative to this? (other than using netsh)
– praveen345
Nov 27 '18 at 12:59
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434145%2fgetting-the-ip-address-of-the-machine-from-batch-scrip-using-virtualbox-host-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
if you have more than one interface, ping
is not helpful. The netsh
command gives you far more flexibity:
for /f "delims=" %%a in ('netsh interface ipv4 show addresses name^="Local Area Connection" ^|find "IP"') do for %%b in (%%a) do set "ip=%%b"
echo Your IP is: %ip%
Change Local Area Connection
to your actual interface name (look for the exact name with netsh interface show interface
)
Thanks Stephan. But, I cannot use this as, I will be using the same batch file across several machines. So, I need the solution to be as generic as possible.
– praveen345
Nov 23 '18 at 13:35
netsh
comes with Windows XP with Service Pack 1 (SP1) and later. I surely hope you are not working with even older Windows versions.
– Stephan
Nov 23 '18 at 13:53
Thanks. Sorry for not mentioning my concern clearly. I cannot use netsh because: I will be using this batch file across several machines and for those machines the interface names might not be same.
– praveen345
Nov 26 '18 at 13:42
ok I understand. But if you have several adapters, how to choose the right one then?ping
obviously can't decide correctly. When I'm right, the address you're looking for is one ofnetsh interface ipv4 show config | find "IP"
? Which one?
– Stephan
Nov 26 '18 at 14:24
I want the one with name "Ethernet". However, I can use the batch file as long as there is no change in the network adapter or network adapter name And if there is any change in the N/W adapter name I need to update the batch file. Although the chance of changing adapter name is less, the chance of using the adapter to "Wi-Fi" is there. Is there any other alternative to this? (other than using netsh)
– praveen345
Nov 27 '18 at 12:59
|
show 1 more comment
if you have more than one interface, ping
is not helpful. The netsh
command gives you far more flexibity:
for /f "delims=" %%a in ('netsh interface ipv4 show addresses name^="Local Area Connection" ^|find "IP"') do for %%b in (%%a) do set "ip=%%b"
echo Your IP is: %ip%
Change Local Area Connection
to your actual interface name (look for the exact name with netsh interface show interface
)
Thanks Stephan. But, I cannot use this as, I will be using the same batch file across several machines. So, I need the solution to be as generic as possible.
– praveen345
Nov 23 '18 at 13:35
netsh
comes with Windows XP with Service Pack 1 (SP1) and later. I surely hope you are not working with even older Windows versions.
– Stephan
Nov 23 '18 at 13:53
Thanks. Sorry for not mentioning my concern clearly. I cannot use netsh because: I will be using this batch file across several machines and for those machines the interface names might not be same.
– praveen345
Nov 26 '18 at 13:42
ok I understand. But if you have several adapters, how to choose the right one then?ping
obviously can't decide correctly. When I'm right, the address you're looking for is one ofnetsh interface ipv4 show config | find "IP"
? Which one?
– Stephan
Nov 26 '18 at 14:24
I want the one with name "Ethernet". However, I can use the batch file as long as there is no change in the network adapter or network adapter name And if there is any change in the N/W adapter name I need to update the batch file. Although the chance of changing adapter name is less, the chance of using the adapter to "Wi-Fi" is there. Is there any other alternative to this? (other than using netsh)
– praveen345
Nov 27 '18 at 12:59
|
show 1 more comment
if you have more than one interface, ping
is not helpful. The netsh
command gives you far more flexibity:
for /f "delims=" %%a in ('netsh interface ipv4 show addresses name^="Local Area Connection" ^|find "IP"') do for %%b in (%%a) do set "ip=%%b"
echo Your IP is: %ip%
Change Local Area Connection
to your actual interface name (look for the exact name with netsh interface show interface
)
if you have more than one interface, ping
is not helpful. The netsh
command gives you far more flexibity:
for /f "delims=" %%a in ('netsh interface ipv4 show addresses name^="Local Area Connection" ^|find "IP"') do for %%b in (%%a) do set "ip=%%b"
echo Your IP is: %ip%
Change Local Area Connection
to your actual interface name (look for the exact name with netsh interface show interface
)
answered Nov 23 '18 at 11:46
StephanStephan
35.9k43457
35.9k43457
Thanks Stephan. But, I cannot use this as, I will be using the same batch file across several machines. So, I need the solution to be as generic as possible.
– praveen345
Nov 23 '18 at 13:35
netsh
comes with Windows XP with Service Pack 1 (SP1) and later. I surely hope you are not working with even older Windows versions.
– Stephan
Nov 23 '18 at 13:53
Thanks. Sorry for not mentioning my concern clearly. I cannot use netsh because: I will be using this batch file across several machines and for those machines the interface names might not be same.
– praveen345
Nov 26 '18 at 13:42
ok I understand. But if you have several adapters, how to choose the right one then?ping
obviously can't decide correctly. When I'm right, the address you're looking for is one ofnetsh interface ipv4 show config | find "IP"
? Which one?
– Stephan
Nov 26 '18 at 14:24
I want the one with name "Ethernet". However, I can use the batch file as long as there is no change in the network adapter or network adapter name And if there is any change in the N/W adapter name I need to update the batch file. Although the chance of changing adapter name is less, the chance of using the adapter to "Wi-Fi" is there. Is there any other alternative to this? (other than using netsh)
– praveen345
Nov 27 '18 at 12:59
|
show 1 more comment
Thanks Stephan. But, I cannot use this as, I will be using the same batch file across several machines. So, I need the solution to be as generic as possible.
– praveen345
Nov 23 '18 at 13:35
netsh
comes with Windows XP with Service Pack 1 (SP1) and later. I surely hope you are not working with even older Windows versions.
– Stephan
Nov 23 '18 at 13:53
Thanks. Sorry for not mentioning my concern clearly. I cannot use netsh because: I will be using this batch file across several machines and for those machines the interface names might not be same.
– praveen345
Nov 26 '18 at 13:42
ok I understand. But if you have several adapters, how to choose the right one then?ping
obviously can't decide correctly. When I'm right, the address you're looking for is one ofnetsh interface ipv4 show config | find "IP"
? Which one?
– Stephan
Nov 26 '18 at 14:24
I want the one with name "Ethernet". However, I can use the batch file as long as there is no change in the network adapter or network adapter name And if there is any change in the N/W adapter name I need to update the batch file. Although the chance of changing adapter name is less, the chance of using the adapter to "Wi-Fi" is there. Is there any other alternative to this? (other than using netsh)
– praveen345
Nov 27 '18 at 12:59
Thanks Stephan. But, I cannot use this as, I will be using the same batch file across several machines. So, I need the solution to be as generic as possible.
– praveen345
Nov 23 '18 at 13:35
Thanks Stephan. But, I cannot use this as, I will be using the same batch file across several machines. So, I need the solution to be as generic as possible.
– praveen345
Nov 23 '18 at 13:35
netsh
comes with Windows XP with Service Pack 1 (SP1) and later. I surely hope you are not working with even older Windows versions.– Stephan
Nov 23 '18 at 13:53
netsh
comes with Windows XP with Service Pack 1 (SP1) and later. I surely hope you are not working with even older Windows versions.– Stephan
Nov 23 '18 at 13:53
Thanks. Sorry for not mentioning my concern clearly. I cannot use netsh because: I will be using this batch file across several machines and for those machines the interface names might not be same.
– praveen345
Nov 26 '18 at 13:42
Thanks. Sorry for not mentioning my concern clearly. I cannot use netsh because: I will be using this batch file across several machines and for those machines the interface names might not be same.
– praveen345
Nov 26 '18 at 13:42
ok I understand. But if you have several adapters, how to choose the right one then?
ping
obviously can't decide correctly. When I'm right, the address you're looking for is one of netsh interface ipv4 show config | find "IP"
? Which one?– Stephan
Nov 26 '18 at 14:24
ok I understand. But if you have several adapters, how to choose the right one then?
ping
obviously can't decide correctly. When I'm right, the address you're looking for is one of netsh interface ipv4 show config | find "IP"
? Which one?– Stephan
Nov 26 '18 at 14:24
I want the one with name "Ethernet". However, I can use the batch file as long as there is no change in the network adapter or network adapter name And if there is any change in the N/W adapter name I need to update the batch file. Although the chance of changing adapter name is less, the chance of using the adapter to "Wi-Fi" is there. Is there any other alternative to this? (other than using netsh)
– praveen345
Nov 27 '18 at 12:59
I want the one with name "Ethernet". However, I can use the batch file as long as there is no change in the network adapter or network adapter name And if there is any change in the N/W adapter name I need to update the batch file. Although the chance of changing adapter name is less, the chance of using the adapter to "Wi-Fi" is there. Is there any other alternative to this? (other than using netsh)
– praveen345
Nov 27 '18 at 12:59
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434145%2fgetting-the-ip-address-of-the-machine-from-batch-scrip-using-virtualbox-host-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Actually your pc has now at least 2 IPv4 addresses, see ipconfig /all.
– LotPings
Nov 22 '18 at 17:08
yes. 1. VirtualBox Host-Only Ethernet Adapter 2. Intel(R) Ethernet Connection I217-LM
– praveen345
Nov 23 '18 at 9:18