Skip to content

Instantly share code, notes, and snippets.

@magnetikonline magnetikonline/README.md
Last active Aug 20, 2019

Embed
What would you like to do?
Modify DHCP DNS servers for Optus supplied (Vividwireless) Huawei B315 4G modem.

Modify DNS for Optus supplied Huawei B315 4G modem

The Huawei B315 modem supplied by Optus for the (now defunt) Vividwireless service is a workable but sadly rather crippled device, even down to the inabiilty to modify assigned DNS servers from it's DHCP server away from Optus DNS to something sane (Google DNS/Cloudflare/etc.).

This script should allow for the easy update of assigned DNS servers and has been tested with Google Chrome.

Usage

  • Log into router web UI (e.g. http://192.168.0.1).
  • From the same browser session, open the "web developer tools" pane.
  • Drop the contents of dnsmodify.js into Console area - modifying ROUTER_URI, PRIMARY_DNS and SECONDARY_DNS to suit.
  • Run the script, updated DHCP settings are pushed and modem will restart.
  • All DHCP leases should now receive updated DNS servers.
  • Settings can be confirmed by:
    • Logging once more into web UI.
    • Visiting http://192.168.0.1/api/dhcp/settings.
    • Look for <PrimaryDns> / <SecondaryDns> elements.

API endpoints of note

  • List of connected Wi-Fi clients: http://192.168.0.1/api/wlan/host-list

Reference

'use strict';
(async () => {
const ROUTER_URI = 'http://192.168.0.1/',
PRIMARY_DNS = '8.8.8.8',
SECONDARY_DNS = '8.8.4.4';
function dhcpSettingsUri() {
return `${ROUTER_URI}api/dhcp/settings`;
}
function xhrReady(xhr) {
return (xhr.readyState == 4) && (xhr.status == 200);
}
function readDHCP() {
return new Promise((resolve) => {
// router doesn't return [Content-Type: text/xml], need to force it
const xhr = new XMLHttpRequest();
xhr.overrideMimeType('text/xml');
xhr.onreadystatechange = () => {
if (xhrReady(xhr)) {
resolve(xhr.responseXML);
}
};
xhr.open('GET',dhcpSettingsUri());
xhr.send();
});
}
function generateVerifyToken() {
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.overrideMimeType('text/xml');
xhr.onreadystatechange = () => {
if (xhrReady(xhr)) {
resolve(xhr.responseXML.querySelector('TokInfo').textContent);
}
};
xhr.open('GET',`${ROUTER_URI}api/webserver/SesTokInfo`);
xhr.send();
});
}
function buildUpdate(current) {
const rootNode = document.implementation.createDocument(null,'request');
for (const el of Array.from(current.firstChild.children)) {
switch (el.tagName) {
case 'DnsStatus':
el.firstChild.textContent = '0';
break;
case 'PrimaryDns':
el.firstChild.textContent = PRIMARY_DNS;
break;
case 'SecondaryDns':
el.firstChild.textContent = SECONDARY_DNS;
break;
}
rootNode.documentElement.appendChild(el);
}
return rootNode;
}
console.clear();
// pull current DHCP settings and generate an update token
const currentDHCP = await readDHCP(),
token = await generateVerifyToken();
// push updated DHCP settings for DNS servers
const xhr = new XMLHttpRequest();
xhr.open('POST',dhcpSettingsUri());
xhr.setRequestHeader('__RequestVerificationToken',token);
xhr.send(
'<?xml version="1.0" encoding="UTF-8"?>' +
(new XMLSerializer()).serializeToString(
buildUpdate(currentDHCP)
)
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.