Commodore
Commodore
418 views

network address attribute

Jump to solution

Hello! Trying to sync the network address syntax attribute. A set of symbols comes in the driver and in the database, as you can see in the attached picture. Tell me how to translate into x.x.x.x form?

0 Likes
1 Solution

Accepted Solutions
Knowledge Partner Knowledge Partner
Knowledge Partner

I wrote an ecmascript to decode netaddr attributes a while ago. It's available in the Bits&Pieces package at https://www.brummelhook.com/download/idm/packages/

Or if you prefer copy&paste:

 

importPackage(Packages.com.novell.xml.util);

function bh_B64ToHex (B64string) {

HEXstring = "";
try {
attrBytes = Base64Codec.decode(B64string);
}
catch (e) {
return "Error: '" + B64string + "' is not a valid base64 encoded string.";
}

for (i = 0; i < attrBytes.length; i=i+1) {
HEXstring += ("00" + attrBytes[i].toString(16)).substr(-2).toUpperCase();
}

return HEXstring;
}

function bh_DecodeNetAddr (B64NetAddr) {

netAddrHex = ("00000000" + bh_B64ToHex(B64NetAddr)).substr(-8);
netAddrIP = "";

for (i = 0; i < 4; i=i+1) {
netAddrIP += parseInt(netAddrHex.substr(i*2,2),16) + ".";
}

return netAddrIP.substr(0,netAddrIP.length - 1);
}

 

PS: You'll find the network types described at https://www.novell.com/documentation/developer/ndslib/nds__enu/data/hniuyp90.html#hniuyp90 . Obviously only types 1, 8 & 9 can be decoded this way.

______________________________________________
https://www.is4it.de/identity-access-management

View solution in original post

3 Replies
Vice Admiral
Vice Admiral

This is a structured attribute so you will need to parse each component.

netAddressType component is set to 1, which is IP

netAddr component holds base64 encoded IP address in binary format (4 bytes, each byte part of IP address).

For example if you base64 decode wKgiZA==, you will get (in HEX):

c0 a8 22 64

Converting that to IP will result in 192.168.34.100

Knowledge Partner Knowledge Partner
Knowledge Partner

I wrote an ecmascript to decode netaddr attributes a while ago. It's available in the Bits&Pieces package at https://www.brummelhook.com/download/idm/packages/

Or if you prefer copy&paste:

 

importPackage(Packages.com.novell.xml.util);

function bh_B64ToHex (B64string) {

HEXstring = "";
try {
attrBytes = Base64Codec.decode(B64string);
}
catch (e) {
return "Error: '" + B64string + "' is not a valid base64 encoded string.";
}

for (i = 0; i < attrBytes.length; i=i+1) {
HEXstring += ("00" + attrBytes[i].toString(16)).substr(-2).toUpperCase();
}

return HEXstring;
}

function bh_DecodeNetAddr (B64NetAddr) {

netAddrHex = ("00000000" + bh_B64ToHex(B64NetAddr)).substr(-8);
netAddrIP = "";

for (i = 0; i < 4; i=i+1) {
netAddrIP += parseInt(netAddrHex.substr(i*2,2),16) + ".";
}

return netAddrIP.substr(0,netAddrIP.length - 1);
}

 

PS: You'll find the network types described at https://www.novell.com/documentation/developer/ndslib/nds__enu/data/hniuyp90.html#hniuyp90 . Obviously only types 1, 8 & 9 can be decoded this way.

______________________________________________
https://www.is4it.de/identity-access-management

View solution in original post

Commodore
Commodore

Thank you so much! That helped! Works great! Is there an inverse conversion function?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.