473,383 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

help converting jscript to C#

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);
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Nov 17 '05 #1
1 1590
Hex literals in C# are written like 0xff

Programme startup is a main method inside a class with the following
signature

[STAThread]
static void Main(string[] args)
{
}

WScript.SdtOut.WriteLine is Console.WriteLine(string).
WScript.StdErr.WriteLine is Console.Err.WriteLine(string)

string[] args array contains the arguments.

These should be enough to develop your utility.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: junk | last post by:
I am converting a large website with VBScript include files and JScript also included as <script language="jscript" runat="server"> in other include files. I would like to convert the VBScript to...
1
by: joe | last post by:
Hello, I have some code written in C that I want to transfer over to JScript so I can run within my project to "burn" my DSP code into EEPROM(Non-volatile RAM). I want to generate an .ldr file (a...
5
by: VM | last post by:
If I have a string variable with a formula: string sMyformula = "3.3*5.2*5"; How can I convert this to a mathematical formula that the compiler can calculate? For all purposes, the formula in...
2
by: junk | last post by:
I am converting a large website with VBScript include files and JScript also included as <script language="jscript" runat="server"> in other include files. I would like to convert the VBScript to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.