.bat for renewing IP until it starts with certain numbers [closed] - batch-file

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
}

Related

CMD/Batch get active internet connection name [closed]

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

receive packet from device is not working as expected [closed]

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 9 years ago.
Improve this question
Here is my configuration
my PC IP :192.168.1.57 subnetmask : 255.255.255.0
my device IP :73.83.1.57 subnetmask : 255.255.255.0
i am successfully able to send packet from my pc to device but not able to send packet from device to pc (have checked in wire shark but it show only PC->device packet transmission flow )
Now i have added one more IP like device ip family in PC (73.83.1.60) then successfully able to two way communication.same works in reverse order means i have set my device IP as 192.168.1.58.
So is there any rules like both IP must belongs to same IP family?
because sub net mask in both are same. so issue is IP.
Any one have idea? is it correct network behavior? can i solve it without making same IP family.?
If you are using both IPs on the same LAN they should be on the same subnet ex:
11.1.1.1/24 can ping 11.1.1.44/24 but it can't ping 11.1.2.2/24 ( different subnets)
In WAN not necessary, for example 192.168.1.1 can ping 72.1.1.1 ,, but 72.1.1.1 can't ping 192.168.1.1 because this ip is private and when it leaves the LAN it becomes real ip because of NAT (Network Address Translation)

New virtual network adapters being assigned randomly [closed]

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/

simple server in C [closed]

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 10 years ago.
Improve this question
I created a simple TCP/IP server in c and it runs smoothly from my Linux machine. I can connect as localhost:80 as well as from different machines, but I obviously have to use the lab computer's IP.
My question is: how do I run a server form my own Mac OS X machine, let's say, and connect to it form outside? Not sure how to properly ask the question... how to assign a specific IP to my server? Sorry, I am still exploring this field!
Thanks!
If your local proxy or box is configured to allow entering connections, the easiest is to assign a fixed name that will be mapped to your (dynamic) IP.
There are a lot of dynamic DNS free solutions on the web (ex : http://www.no-ip.com/)
If you just want to make a one time test, you can see what IP you have with a service like this one : http://www.whatismyip.com/
All you need is a machine that has globally routable static ip address. And run your server on that machine.
Running it on your Mac laptop is okay but as you hop from one wifi network to other your server is no longer available.
Best way is to find a machine , a desktop in your lab or ar home connected to say comcast isp that has a static globally rout able ip and run your server on there.

Recovering from ipconfig /release on a remote PC [closed]

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
Not strictly a programming question, but I was programming at the time and couldn't find an answer, so I thought, "Hey, I'll give StackOverflow a try!"
So I'm connected to my Windows XP work PC over a Remote Desktop connection through VPN. In a command window (on the remote PC), I foolishly type ipconfig /release. A split second before I come to my senses, I hit Enter. D'oh!
So what now? Am I hosed until I get to the office Monday morning? Any way to remotely make my office PC get itself a new IP address?
If it makes you feel any better, most of us have done something similar. I can't offer a suggestion that doesn't involve human intervention, but I can offer two ways to prevent a "next time" for you:
Look into a remote power controller. Cheap (inexpensive, hobbyist-grade) options are available through www.x10.com; other vendors (Pulizzi, DataProbe, etc.) provide more reliable solutions for a higher price. You may even be able to find a UPS that allows you to control it via a serial port.
Plug your PC into the power controller, and find a second PC to control it. Now you can reboot your PC remotely, no matter how badly you de-configure it.
Anticipate and compensate. It's reasonable to expect that you may need to release/renew the IP address again, so write a utility that will check for the loss of IP address and reboot if that occurs. For example, ping your default gateway and reboot if the ping fails consistently. Just be sure to anticipate the consequences of an unexpected reboot!
Try giving a call to the office and get someone(if any) to restart your computer or ipconfig /renew
What you need to do, is find some way to cut the power to your PC. Many PCs are configured by default to reboot if there is a power failure. So, just hack into your power grid, and shut off power to the entire building. Once your computer reboots, along with all the other equipment, your computer should have it's IP back.
(This probably won't work)
I think if you get your network connection severed, it'll reset (like, if I run ipconfig /release, then shut off my router and restart it, I get a new IP).
It'd be well winging it, but if I was desperate I'd hook up to my DHCP server and reboot it.. I predict the end result would be me still not being able to connect, and the admins giving me a good whipping.
Log into the managed switch the PC is connected to, shutdown the port, wait a few seconds, and then bring it back up. If you don't have a managed switch or no access to it, wait until Monday.

Resources