Sign in to follow this  
Followers 0
enaiman

JavaScript and MAC address

4 posts in this topic

Sorry for such a title; it seem to be too hard to give an accurate title.

Basically I have a list of MAC addresses in a text format (0.192.65.3.36.66, ....) and so on and I would like to get it in a "hex" format (0.C0.41.3.24.42, ...)

The problem is: the application handling these MAC addresses uses xml and Java Script and the only way to get these "transformed" is to put a chunk of code in an <expression> tag ...

I've spent several hours trying to figure how to do it without much success.

So far I have managed to successfully do the following:

- use a regEx to get matches for "numbers"

- replace the matches with something else

Problems?

- the matches are regarded as strings (not numbers) and I have no idea how to continue

Here is the code I have attempted so far:

var str="0.142.9.33.58.6";
var patt1=/\d{1,}/g;

str2=str.replace(patt1, "match");
document.write(str2);

This script is successfully replacing the matches with "match" - how can I replace the matches with their hex value??

I'm really stuck here (heh - I wish that application could use some AutoIt ...) and I will appreciate any help.

Thanks alot,

- the code can be tested here, just replace the code between the html tags and the result can be seen immediately.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites



What you'll have to do is parse each piece to a number. Then you just convert it back to a string.

myfifteen = parseInt("15"); // you'd parse each section of the number.
myfifteenhex = myfifteen.toString(16); // this converts the number to a string in base 16 (hex)

Your enumeration and replacement will have to be a two step process. First read the number, perform the conversion, and then make the replacement.

Share this post


Link to post
Share on other sites

Thank you very much for your help.

I have managed finally to write a script to do that, just to discover that I cannot use a script :D - actually what I can use is very limited.

Well, I guess I'll have to find another way.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Well good luck then.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0