Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I know how to get interface name
netsh interface show interface
I also know how to get wifi's names
netsh wlan show profiles
If I'm connected to Wi-Fi 2 adapter then I will be connected to one of the wlan profiles.
How can I can get same profile name to lan connection? It should be "TP-Link 2.4 2" according to my network connection settings. But if I try
netsh lan show profiles
All I get is "The Wired AutoConfig Service (dot3svc) is not running."
Ultimate goal is to print active connection name, so if ethernet 2 is active then TP-Link 2.4 2, if wi-fi is active then for example TP-Link_2064
EDIT: I activated wired autoconfig in services.msc. Now
netsh lan show profiles
gives me this
but still there is no name of ethernet. I wonder where it gets into windows 10, because I surely didn't type name of ethernet.
If you have a single active connection at any one time, this should provide you with the information you need?
batch-file
#Echo Off & SetLocal EnableExtensions
Set "Name=" & Set "NetConnectionID="
For /F Delims^= %%G In ('%__APPDIR__%wbem\WMIC.exe NIC Where ^
"Not NetConnectionStatus Is Null And NetEnabled='TRUE'" ^
Get Name^,NetConnectionID /Value 2^> NUL') Do Set "%%G" 2> NUL 1>&2
If Not Defined Name GoTo :EOF
Echo You are currently connected to Interface "%NetConnectionID%" on "%Name%"
Pause
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
My ISP, unfortunately, has different routes for different IPs, so pings are drastically different as well. Can someone please help me to write a .bat which performs ipconfig /release && ipconfig /renew until IP starts with some value? (I noticed that IPs starting with 147...* have the lowest ping)
here is a powershell script that will do the job:
[string]$ip = (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
while(!$ip.StartsWith('147')){
ipconfig /release *con*
ipconfig /renew
$ip = (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
}
please put the number that you want your ip to start with inside the loop condition, it will continue to release and renew until you get an ip that starts with that number.
Well your ISP may or may not change your IP address for a while, even if it is dynamic. I can only suggest going into your router's setting and releasing your WAN IP address and renewing it or simply restarting the router.
Note : for your request ipconfig /release / renew doesn't affect your external/ ISP IP address it renews the internal IP Address.
to release and renew you're internal ip address you can run the bellow commands in powershell:
ipconfig /release *Con*
ipconfig /renew
to get your external ip address you can use powershell to invoke a web request:
[string]$ip = (Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
and then you can check if that ip starts with a specific number:
if($ip.StartsWith('147')){
#some code here
}
I'm writing a script to revert the network settings back to default which is to switch back to DHCP on LAN and re-enable the wireless adapter. All these operations were done under the local admin rights privileges for all devices that I'm managing.
While the switching over to DHCP from static works, the script was unable to re-enable the wireless adapter and showing "No more data is available". I had did a bit of troubleshooting and found out that the disabled wireless adapter is not reflected in the ipconfig /all command which I have been using it to obtain the adapter name (e.g Wi-Fi, Wi-Fi 2, etc.) thus the netsh command gave the error due to the varible being invalid.
Here is the part of the code that's responsible for the re-enabling the wireless adapter back. I'm aware that if I were to enter the netsh interface set interface name="Wi-Fi" admin=enabled manually it works based on the adapter name that's taken on my test device. But however I can't hard-code the adapter name as it may not be the same for different devices. Do share if there's any other code for the first line that I might not be not aware of as I did many googling and it only came up with either for the ipconfig or wmic command. Thanks!
::Look for the Wi-Fi adapter name
for /f "tokens=* delims=:" %%b in ('ipconfig ^| find /i "Wireless LAN adapter Wi-Fi"') do set wifiadaptername=%%b
set wifiadaptername=%wifiadaptername:~21%
set wifiadaptername=%wifiadaptername:~0,-1%
::Switch on Wi-Fi
netsh interface set interface name="%wifiadaptername%" admin=enabled
Could anyone help me force all network adapters to be DHCP whether connected or disconnected.
I am relatively new and very novice in batch and I have been working on something to set fixed ipv4 details based on variable Ethernet adapter names. It has been cobbled together from other people's solutions to various problems on here. I am sure there are much more eloquent and elegant ways of doing this and happy to be pointed that way but I would like to try and figure this out.
The idea was to have a call batch script in the startup folder of a OOBE windows machine. Search the connected adapter, irrelevant of the name of said port, set the IP address as static and rest of the details were fixed. I wrote the batch in such a way as to create various IP profiles using variables to create the profile to set the fixed details i.e. a batch to write a batch
As an exercise I was thinking if I were to move the machine and plug in a different adapter on the same machine. How would I have a disconnected adapter with the IP address I want to use switch to DHCP. This would free up the address to search for connected adapter as per the rest of the script. This is where the script fails. I can have the connected adapter switch tp DHCP, disable and enable correctly.
WMIC NICConfig Where "IPEnabled='True' and DHCPEnabled='FALSE'" Call EnableDHCP
this works but only on the connected adapter.
But I am trying to flush out the IP address on the disconnected adapter to use on the connected adapter. So far I've tried
WMIC NICConfig Where NetConnectionID=7 Call EnableDHCP
returns a "Description = Invalid query"
WMIC NICConfig Where "PhysicalAdapter='True'" Call EnableDHCP
returns a "Description = Invalid query"
WMIC NICConfig Where "DHCPEnabled='FALSE'" Call EnableDHCP
returns {ReturnValue = 84;}; I thought this would search for adapters that were not DHCP and change to to be DHCP but I think the adapter has to be connected.
When I use
WMIC NICConfig Where "PhysicalAdapter='True'" Call /?
EnableDHCP looks to be an option but gives a "Description = Invalid query"
Is there a way to do what I am trying to do?
I can also post the entire script if anyone is interested in it but will leave it off until requested. Thanks in advance for any help.
I figured this out.
I was going about it the complete wrong way.
I was trying to clear all adapters fixed ip addresses by "forcing" the physical adapter to DCHP weather connected or disconnected.
But if I have had said
netsh int ip reset
wmic path win32_networkadapter where PhysicalAdapter=True call disable
wmic path win32_networkadapter where PhysicalAdapter=True call enable
This achieves what I want. This clears the IP, subnet and gateway. Sometimes the solution is much easier than expected.
Is there a way to clear the DNS information too for all physical adapters, without knowing their names, so that if IPV4 properties is open no information would be there?
I am currently writing a .bat script in which you can choose whether you want to create an ad-hoc-network or connect to one, to make it easy for everyone to connect within windows 8, 8.1 and 10 as the GUI setup was removed.
Well, creating was easy.
netsh wlan set hostednetwork mode=allow ssid=adhocnetwork key= password
netsh wlan start hosted network
pause
But when I want to connect to a network via netsh wlan connect adhocnetwork, it says there is no profile called 'adhocnetwork'.
I figured that you first have to create a profile with the network GUI.
So my question is now if there is a way to create a network profile with the command line, so that I can implement that into the bat file.
Thanks for every answer!
Best greetings,
Bant
Okay, well, here is my workaround.
Go to the network and sharing center (hope that's right, my system is in German)
Manually create wireless network and type in the name, security type and key.
Remove the tag from 'connect automatically'.
Press 'Done'
Now open the command line and type in the following lines:
netsh wlan set profileparameter name=%name% ConnectionType=IBSS
netsh wlan connect name=%name%
I am still hoping for a better solution where you don't need to leave the command shell.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a setup where I clone virtual machines, therefore changing their mac addresses.
When each machine boots up, it gets assigned to a Local Area Connection x interface.
I then run a batch script that changes the IPs of the interfaces:
netsh interface ip set address name="Local Area Connection 1" static 192.168.1.50 255.255.255.0 192.168.1.254
netsh interface ip set address name="Local Area Connection 2" static 172.16.5.50 255.255.255.0 172.16.5.254
The problem is that the adapters gets assigned randomly - the first NIC sometimes gets Local Area Connection 1 and sometimes Local Area Connection 2. Therefore I can't assign the IP addresses.
The NICs are ordered correctly by their MAC addresses. I've thought about getting the MAC addresses of the two active interfaces, sort them, and find out the assigned adapter names, and only then run netsh interface ip set, however I'm not sure how can I do it.
Any ideas?
I used the getmac util to get the MAC addresses along with their assigned connection names:
getmac /V /FO LIST
There is also a solution with Powershell:
http://www.ddls.net.au/blog/2012/08/renaming-network-connections-using-powershell-and-wmi/