Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Help me with the syntax of this bat file that changes my ip address

10 Sep 2015   #1
Delta 7

Windows 7
 
 
Help me with the syntax of this bat file that changes my ip address

netsh interface ip set address name="Wireless
Network Connection" static 192.168.1.64
255.255.255.0
192.168.1.%RANDOM% * (%300% - %1% + 1);

#//192.168.1.254
#//%RANDOM% * (%888% - %01% + 1)
#//%RANDOM% * (%maxval% - %minval% + 1) / 32768 + %minval%;

Wont work, and in shell scripting what makes the line dormant? the # or // ?


My System SpecsSystem Spec
.
10 Sep 2015   #2
GokAy

Windows 7 Ultimate x64 SP1
 
 

I will ask one of our programming experts, he may not be checking this section of the forums.
My System SpecsSystem Spec
10 Sep 2015   #3
Delta 7

Windows 7
 
 

Quote   Quote: Originally Posted by GokAy View Post
I will ask one of our programming experts, he may not be checking this section of the forums.
Let me know what he says
My System SpecsSystem Spec
.

11 Sep 2015   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Hi Delta,

I'm finding it difficult to help you as you haven't yet explained what your batch file is to do, or the problem/s you are having with your current script (there are quite a few). And the batch file you've posted makes it none the clearer to me of your intent: # and // at the beginning of a command line is nothing more than a syntax error to me.

Meanwhile, this may help -- here is a small example of a batch file that changes one's IP address to 192.168.1.x, where x is any integer between 10 and 255 (inclusive).
Code:
@echo off

set interface_name="Wireless Network Connection"
set ipaddr_front=192.168.1
set /a ipaddr_end=(255 * %RANDOM%)/32768+10
set subnet_mask=255.255.255.0

netsh interface ip set address %INTERFACE_NAME% static %IPADDR_FRONT%.%IPADDR_END% %SUBNET_MASK%
My System SpecsSystem Spec
11 Sep 2015   #5
GokAy

Windows 7 Ultimate x64 SP1
 
 

Thanks for your input Pyprohly.

255 should not be included (for this case), it is the broadcast address for the network for this subnet mask (255.255.255.0). (the last IP in the subnet is broadcast, so may be different for classless networks). Say, for example, for 255.255.0.0 subnet you can have an IP ending as 0.255 or 1.255 etc but not 255.255
My System SpecsSystem Spec
11 Sep 2015   #6
UsernameIssues

W7 Pro SP1 64bit
 
 

Some network devices will not accept traffic from IP addresses that are outside or the DHCP range.

e.g. if the DHCP range is 192.168.1.100 to 192.168.1.150 and the batch file assigns the computer 192.168.1.15, then no traffic will flow to that computer. The vendor claimed this is a security feature. I called it an annoyance.
My System SpecsSystem Spec
11 Sep 2015   #7
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

@GokAy Have I made an obvious mistake somewhere? Please elaborate if so.
My System SpecsSystem Spec
11 Sep 2015   #8
GokAy

Windows 7 Ultimate x64 SP1
 
 

Sorry for not being clear about it.

Quote:
where x is any integer between 10 and 255 (inclusive).
It should be 254 max in this case. So,
Code:
set /a ipaddr_end=(255 * %RANDOM%)/32768+10
should be
Code:
set /a ipaddr_end=(254 * %RANDOM%)/32768+10
right?
My System SpecsSystem Spec
11 Sep 2015   #9
GokAy

Windows 7 Ultimate x64 SP1
 
 

And something I noticed right now, if you are adding 10 by default, it should be 244 instead?

I get %RANDOM% returns an integer between 0 (or 1?) and 32768?

Ok, did some searching and it is 0-32768.

Also found this,

what do you think about?
Code:
set /a ipaddr_end=%RANDOM% %%244 +10
I tested in cmd, there %RANDOM% % 244+10 seem to work (single % before 244 instead of %% in script)
My System SpecsSystem Spec
11 Sep 2015   #10
Delta 7

Windows 7
 
 

Quote   Quote: Originally Posted by Pyprohly View Post
Hi Delta,

I'm finding it difficult to help you as you haven't yet explained what your batch file is to do, or the problem/s you are having with your current script (there are quite a few). And the batch file you've posted makes it none the clearer to me of your intent: # and // at the beginning of a command line is nothing more than a syntax error to me.

Meanwhile, this may help -- here is a small example of a batch file that changes one's IP address to 192.168.1.x, where x is any integer between 10 and 255 (inclusive).
Code:
@echo off

set interface_name="Wireless Network Connection"
set ipaddr_front=192.168.1
set /a ipaddr_end=(255 * %RANDOM%)/32768+10
set subnet_mask=255.255.255.0

netsh interface ip set address %INTERFACE_NAME% static %IPADDR_FRONT%.%IPADDR_END% %SUBNET_MASK%

This is the original script

netsh interface ip set address name="Wireless Network Connection" static 192.168.1.64 255.255.255.0 192.168.1.254;

its supposed to change any variable inbetween each dot within each address
My System SpecsSystem Spec
Reply

 Help me with the syntax of this bat file that changes my ip address




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Copy file address after doing a file search in windows explorer
Hi All I have a rather large file system with lots of folders & subfolders. When I want to save previously on Xp operating system I'd search in explorer open the folder I want then copy the address (e.g c:\customer records\client name\job address). In windows 7, when I copy the folder address i...
General Discussion
How to make File Explorer display full address of files in search
I have done a search and file explorer returns some results. You can see the locations of each file are chopped off. But there is no grid splitter allowing me to expand the filename column. How can I view the whole address of the files in Search results?
General Discussion
Batch file syntax file
I'm trying to create a batch file that will copy some excel files from my usb drive to my c: . this is what I'm putting in the command line. e: cd excelbak\exlbak13 copy *.* c:\program files\microsoft office\office12\excel comment I get is invalid sytanx in command line...I'm thinking that...
Performance & Maintenance
host file/ loopback address broken cannot update AV/loginto WLM
Hi guys, this has been going for a couple of days now, I cannot loginto windows live messenger and cannot update my avira free edition anti virus So I tried updating my AV one night and found that I could not - kept coming up with an error... I could browse the web and torrent etc and so I...
Network & Sharing
Proper exact address syntax?
If I would like to point one PC at the exact address of another PC over the internet, NOT a local area network, how would it look? http:293.86.45.567.123:192.168.0.199 (example, don't try it, probably some creep's ip, lol!) I have tried googling syntax, address etc. but I am just lost, and...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 15:02.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App