JS to pull IP address and execute time sync file based on first 2 octets of IP address.

Hi SOTI Community it's me again lol: I'm new to JS and learning with Code Academy and God! Today I'm struggling with 1. pulling the IP address from my device details page 2. executing a time sync XML file in JS (I already have the time sync file synced to the device). 

This is only pieces of my code that I'm currently working on: The end goal is to be able to:

1. write the device details to a new file on my sd card  ( I have most of this but the IP address is not working)

2. read the contents of the file to grab the ip address ( i think i have this working, it's just pulling wrong information)

3. based on that ip address, execute a specific time zone file ( i don't know how to execute my XML file in JS to apply the time zone on the device)

Here is the code I have so far: 

var folderPath = '/sdcard/DeviceInfo';
var deviceId = mobicontrol.device.id;
var deviceMAC = mobicontrol.device.macAddress;
var ipAddresses = mobicontrol.network.activeNetwork.ipAddresses;
var deviceIP = ipAddresses[0].hostAddress
var xmlString = '<?xml version="1.0" encoding="utf-8"?>\n' +
'<deviceinfo>\n' +
' <device id="' + deviceId + '"/>\n' +
' <device macaddress="' + deviceMAC + '"/>\n' +
' <device ip="' + deviceIP + '" />\n' + '</deviceinfo>';
var xmlFile = new mobicontrol.io.File('/sdcard/DeviceInfo/DeviceInfo.xml');
checkFolder();
function checkFolder() {
var foldercheck = new mobicontrol.io.File(folderPath);
if (foldercheck.exists) {
mobicontrol.log.info('Folder exists');
}
else {
mobicontrol.log.info('Folder does not exist.')
newFolder();
};
}
newFolder();
function newFolder() {
new mobicontrol.io.File(folderPath).createDirectory();
}
xmlFile.writeText(xmlString);
var xmlContent = xmlFile.readText(deviceId);
mobicontrol.log.info('Device ID: ' + deviceId);
 
 
the output for the IP address was working before but today when i try it is giving me this: *i modified the file but everything is showing correct but the IP address* it is not giving me the actual IP anymore of 10.1.X.X
 
Any help at all or a point in the right direction is greatly appreciated!!!
a year ago
Android Scripting
ANSWERS

The IP you see here looks like an IPV6 address but seem too short.

Maybe you should check if the network the device is connected to, provides ipv6 addresses instead of ipv4 or if you really got the correct ip address as you always point to the first entry

but you can check if its' ipv6 with isIpv6 which provides a boolean value.

A
ATMOD@SOTI
a year ago

Hi Katie,

 

Thanks for posting on SOTI Pulse.

Thanks Rafael for responding to the post, your expertise and willingness to help are greatly appreciated! Has your query been resolved? If this post did not assist you in resolving the issue, I believe an investigation would be necessary. It is highly recommended that you log a case so that we can delve deeper into the matter.  I would suggest you to contact SOTI Support (support@soti.net) to open a new case and one of our support engineer will be there to assist you.

 

Kind Regards,

Technical Support | SOTI Inc. |1.905.624.9828 | support@soti.net | www.soti.net |