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

Delta 7

New member
Local time
12:54 PM
Messages
10
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 Computer My Computer

Computer type
PC/Desktop
OS
Windows 7
I will ask one of our programming experts, he may not be checking this section of the forums.
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 SP1
CPU
AMD Phenom 2 1090T
Motherboard
Gigabyte GA-890FXA-UD5
Memory
2x8GB Kingston HyperX Fury Black 1600Mhz Unganged
Graphics Card(s)
MSI GTX 970 Gaming 4G
Sound Card
Realtek On-Board HD 7.1 Audio / Logitech G35
Monitor(s) Displays
3xAcer GD245HQ
Screen Resolution
1920x1080
Hard Drives
Samsung 850 Pro 512GB SSD - OS /
WD Caviar Black SATA 3 - 1 TBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GB - Internal Backup /
Seagate Barracude SATA 3 - 3TB - External Backup/ Sync
PSU
HighPower 1000W
Case
Cooler Master HAF 932
Cooling
Noctua NH-D14
Keyboard
Logitech G19
Mouse
Logitech G500
Internet Speed
100/4 Mbit Cable (100GB quota)
Antivirus
ZoneAlarm Extreme Security / MBAM Pro / MBAE Free / SAS Free
Browser
IE 11 - Firefox - Chrome
Other Info
Logitech F710/ G27/ G940/ Z5500 // TrackIR 5 // Nvidia 3D Surround Vision
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 Computer My Computer

Computer type
PC/Desktop
OS
Windows 7
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 Computer My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
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 Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 SP1
CPU
AMD Phenom 2 1090T
Motherboard
Gigabyte GA-890FXA-UD5
Memory
2x8GB Kingston HyperX Fury Black 1600Mhz Unganged
Graphics Card(s)
MSI GTX 970 Gaming 4G
Sound Card
Realtek On-Board HD 7.1 Audio / Logitech G35
Monitor(s) Displays
3xAcer GD245HQ
Screen Resolution
1920x1080
Hard Drives
Samsung 850 Pro 512GB SSD - OS /
WD Caviar Black SATA 3 - 1 TBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GB - Internal Backup /
Seagate Barracude SATA 3 - 3TB - External Backup/ Sync
PSU
HighPower 1000W
Case
Cooler Master HAF 932
Cooling
Noctua NH-D14
Keyboard
Logitech G19
Mouse
Logitech G500
Internet Speed
100/4 Mbit Cable (100GB quota)
Antivirus
ZoneAlarm Extreme Security / MBAM Pro / MBAE Free / SAS Free
Browser
IE 11 - Firefox - Chrome
Other Info
Logitech F710/ G27/ G940/ Z5500 // TrackIR 5 // Nvidia 3D Surround Vision
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.
 
Last edited:

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Employer provided Dell Latitude
OS
W7 Pro SP1 64bit
CPU
i7
Memory
8GB
Graphics Card(s)
Intel HD Graphics
Hard Drives
crappy SSD
Antivirus
Employer mandated Symantec Endpoint Protection
Browser
Pale Moon 64bit, IE11 64bit & Chrome 64bit
@GokAy Have I made an obvious mistake somewhere? Please elaborate if so.
 

My Computer My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Sorry for not being clear about it.

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=([COLOR=red]254[/COLOR] * %RANDOM%)/32768+10
right?
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 SP1
CPU
AMD Phenom 2 1090T
Motherboard
Gigabyte GA-890FXA-UD5
Memory
2x8GB Kingston HyperX Fury Black 1600Mhz Unganged
Graphics Card(s)
MSI GTX 970 Gaming 4G
Sound Card
Realtek On-Board HD 7.1 Audio / Logitech G35
Monitor(s) Displays
3xAcer GD245HQ
Screen Resolution
1920x1080
Hard Drives
Samsung 850 Pro 512GB SSD - OS /
WD Caviar Black SATA 3 - 1 TBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GB - Internal Backup /
Seagate Barracude SATA 3 - 3TB - External Backup/ Sync
PSU
HighPower 1000W
Case
Cooler Master HAF 932
Cooling
Noctua NH-D14
Keyboard
Logitech G19
Mouse
Logitech G500
Internet Speed
100/4 Mbit Cable (100GB quota)
Antivirus
ZoneAlarm Extreme Security / MBAM Pro / MBAE Free / SAS Free
Browser
IE 11 - Firefox - Chrome
Other Info
Logitech F710/ G27/ G940/ Z5500 // TrackIR 5 // Nvidia 3D Surround Vision
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 Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom Build
OS
Windows 7 Ultimate x64 SP1
CPU
AMD Phenom 2 1090T
Motherboard
Gigabyte GA-890FXA-UD5
Memory
2x8GB Kingston HyperX Fury Black 1600Mhz Unganged
Graphics Card(s)
MSI GTX 970 Gaming 4G
Sound Card
Realtek On-Board HD 7.1 Audio / Logitech G35
Monitor(s) Displays
3xAcer GD245HQ
Screen Resolution
1920x1080
Hard Drives
Samsung 850 Pro 512GB SSD - OS /
WD Caviar Black SATA 3 - 1 TBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GBx2 - Dynamic RAID 0 /
WD Caviar Green SATA 2 - 640GB - Internal Backup /
Seagate Barracude SATA 3 - 3TB - External Backup/ Sync
PSU
HighPower 1000W
Case
Cooler Master HAF 932
Cooling
Noctua NH-D14
Keyboard
Logitech G19
Mouse
Logitech G500
Internet Speed
100/4 Mbit Cable (100GB quota)
Antivirus
ZoneAlarm Extreme Security / MBAM Pro / MBAE Free / SAS Free
Browser
IE 11 - Firefox - Chrome
Other Info
Logitech F710/ G27/ G940/ Z5500 // TrackIR 5 // Nvidia 3D Surround Vision
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 Computer My Computer

Computer type
PC/Desktop
OS
Windows 7
@GokAy I used the random number function SS64 used here. They use a function like,
Code:
[I]f(min, max) = floor(randint(0, 32767) * max / 32768) + min[/I]
I tested with different max and min values and I found that with some pairs of max and min the function returns numbers greater than the max. Though their example of f(0,500) seems to work OK :huh:.

For example, try f(50, 100)
Code:
set /a rand=%RANDOM%*100/32768+50
It tends to return numbers greater than 100 fairly often.

The same thing happens with your function, Gokay, of,
Code:
[I]f(min,max) = randint(0, 32767) % 244 + 10[/I]
it occasionally generates numbers greater than the given max, 244. Again, this is more apparent if you pass in numbers more closer to each other, e.g. f(50, 100).


Here are the corrected functions,
Code:
[I]f(min, max) = floor(randint(0, 36727) * (max-min+1) / 32767) + min[/I]
and
Code:
[I]f(min, max) = rand(0, 36727) % (max-min+1) + min[/I]
which translates into Batch as
Code:
set /a rand=%RANDOM% * (%MAX%-%MIN%+1) / 32768 + %MIN%
and
Code:
set /a rand=%RANDOM% %% (%MAX%-%MIN%+1) / 32768 + %MIN%
respectively.

I guess I'll be using the above line to retrieve random numbers when in Batch from now on.


[...] (single % before 244 instead of %% in script)
Other way 'round. Double percent in script, single percent on command line.


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
For example?
 

My Computer My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Back
Top