I wrote a program in jscript that takes two arguments:
1. Location
2. Number
The purpose of script generates a IP that is different for each location and
used to assign Distribution Center addresses to hardware. The first
arugument checks a case statement and determines the starting address.(It
was easier to add via hex) Second argument is the number and the purpose is
incrementing the number in the Ip range to spit out a different addess.
For example,
GenerateIPAddress.js DC1 0001 - The address is 10.160.1.2
GenerateIPAddress.js DC1 0002 - The address is 10.160.2.2
Each time the third octet is incrmented based on number, so this is a
255.255.255.0 network.
I need to convert to a c# executable and do not know how to do it. I do not
know how to do the hex work in c# and asking for help. Any help would be
definently appreaciated. The code is below.
----------------------------------------------------------------------------------------------------------------------------------
switch(WScript.Arguments.Item(0).toUpperCase())
{
case "DC1":
name="DC1";
ipbase=0x0AA00000;
max=4064
break;
case "DC2":
name="DC2";
ipbase=0x0A600000;
max=4064
break;
case "DC3":
name="DC3";
ipbase=0x0AB00000;
max=4064
break;
case "DC4":
name="DC4";
ipbase=0x0A700000;
max=4064
break;
default:
WScript.StdErr.WriteLine();
WScript.StdErr.WriteLine("Could Not Detect DC AREA");
WScript.StdErr.WriteLine("The LOCATION entered, '" +
WScript.Arguments.Item(0) + "', is not a valid LOCATION");
WScript.Quit(2);
}
//Argument 1 is the LOCATION
var number=WScript.Arguments.Item(1)
range=256;
ipaddress=range*number+ipbase+0;
// Need to add 512 at certain number numbers to skip ranges not availiable.
if (number>254) ipaddress=ipaddress+512
if (number>508) ipaddress=ipaddress+512
if (number>762) ipaddress=ipaddress+512
if (number>1016) ipaddress=ipaddress+512
if (number>1270) ipaddress=ipaddress+512
if (number>1524) ipaddress=ipaddress+512
if (number>1778) ipaddress=ipaddress+512
if (number>2032) ipaddress=ipaddress+512
if (number>2286) ipaddress=ipaddress+512
if (number>2540) ipaddress=ipaddress+512
if (number>2794) ipaddress=ipaddress+512
if (number>3048) ipaddress=ipaddress+512
if (number>3302) ipaddress=ipaddress+512
if (number>3556) ipaddress=ipaddress+512
if (number>3810) ipaddress=ipaddress+512
// this converts the number to a HEX string
ipstring=ipaddress.toString(16);
// the next four lines slice the string into 4 "octets"
octet1="0x"+ipstring.substring(0,1);
octet2="0x"+ipstring.substring(1,3);
octet3="0x"+ipstring.substring(3,5);
octet4="0x"+ipstring.substring(5,7);
octet1=octet1*1;
octet2=octet2*1;
octet3=octet3*1;
octet4=octet4*1;
octet4=octet4*1+2;
DeviceIP=(octet1 + "." + octet2 + "." + octet3 + "." + octet4);
//Output to the console
WScript.StdOut.WriteLine(DeviceIP);
-------------------------------------------------------------------------------------------------------------------------------------------------------------------