Salamek / huawei-lte-api

API For huawei LAN/WAN LTE Modems
GNU Lesser General Public License v3.0
376 stars 92 forks source link

Change IP request #209

Closed alex-eri closed 6 months ago

alex-eri commented 6 months ago

I used this code to change modem ip address

void function () { 
    var a = prompt("Current IP 192.168.?.1 [8]", 8); 
    sModemIp = "192.168." + a + ".1"; 
    var b = prompt("New IP 192.168.?.1 [1]", 1);
    sXmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><DnsStatus>1</DnsStatus><DhcpStartIPAddress>192.168." + b + ".100</DhcpStartIPAddress><DhcpIPAddress>192.168." + b + ".1</DhcpIPAddress><accessipaddress></accessipaddress><homeurl>hi.link</homeurl><DhcpStatus>1</DhcpStatus><DhcpLanNetmask>255.255.255.0</DhcpLanNetmask><SecondaryDns>192.168." + b + ".1</SecondaryDns><PrimaryDns>192.168." + b + ".1</PrimaryDns><DhcpEndIPAddress>192.168." + b + ".100</DhcpEndIPAddress><DhcpLeaseTime>86400</DhcpLeaseTime></request>"; 
    var c = new XMLHttpRequest; 
    c.open("GET", "http://" + sModemIp + "/api/webserver/SesTokInfo", !0), 
    c.overrideMimeType("text/xml"), 
    c.onreadystatechange = function () { 
        if (c.readyState == 4 && c.status == 200 && c.responseXML) { 
            var a = c.responseXML.querySelector("SesInfo").innerHTML,
            b = c.responseXML.querySelector("TokInfo").innerHTML, 
            d = new XMLHttpRequest; 
            d.open("POST", "http://" + sModemIp + "/api/dhcp/settings", !0), 
            d.setRequestHeader("Content-Type", "text/xml; charset=UTF-8"), 
            d.setRequestHeader("__RequestVerificationToken", b), 
            d.setRequestHeader("Cookie", a), 
            d.onreadystatechange = function () {
                4 == d.readyState &&
                200 == d.status && 
                alert("IP Changed")
             },
            d.send(sXmlData) 
        } 
    }, 
    c.send(null) 
}();

Can I change IP with your library?

Salamek commented 6 months ago

Yes:

https://github.com/Salamek/huawei-lte-api/blob/af6c9e05ca3c0d7c40133994fb8af735e1525ce0/huawei_lte_api/api/Dhcp.py#L27-L74