import QtQuick 2.6 import QtQuick.Window 2.2 import gfa.plugins.qml.net 1.0 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Text { id: idIpAddr x: 5 y: 40 color: "blue" font.pixelSize: 14 text: idItf.interfaces[2].inet.stat.ipAddress.address } Text { id: idIfUpDownOut x: 5 y: 60 width: 630 height: 300 color: "black" font.pixelSize: 14 text: "" } NetInterfaces { id: idItf // itfFilterName: "eth0" itfFilterAF: Interface.AF_Inet | Interface.AF_Inet6 itfFilterMethod: Interface.IM_Static | Interface.IM_Manual onError: { console.error(msg); } onFilteredInterfacesChanged: { // console.warn("Filtered Interfaces may have changed!"); } onIfUpDown: { idIfUpDownOut.text += msg; // console.log(msg); } onIfUpDownCompleted: { switch(ctx) { case NetInterfaces.UDC_Start: console.log("IfUp completed with code " + code); break; case NetInterfaces.UDC_Stop: console.log("IfDown completed with code " + code); break; case NetInterfaces.UDC_Restart: console.log("IfUpDown completed with code " + code); break; } } } MouseArea { anchors.fill: parent onClicked: { var ret; idIfUpDownOut.text = ""; // idIfUpDownOut.update(); // return; if(idItf.filteredInterfaces.length > 0) { idItf.filteredInterfaces[0].inet.stat.ipAddress.address = "155.18.2.156"; idItf.filteredInterfaces[0].inet.stat.ipAddress.b2 = 255; // console.log(idItf.filteredInterfaces[0].inet.stat.ipAddress.address); } else { console.warn("No interface found!"); } idItf.itfFilterMethod &= ~Interface.IM_Manual; idItf.itfFilterMethod |= Interface.IM_Dhcp; var itfn = idItf.newInterface("test1", Interface.AF_Inet6, Interface.IM_Dhcp); itfn.af = Interface.AF_Inet; itfn.method = Interface.IM_Static; itfn.inet.stat.ipAddress.address = "192.168.3.24"; itfn.inet.stat.netMask.address = "255.255.254.0"; itfn.inet.stat.netPrefix = 22; itfn.inet.stat.gateway.b0 = 192; itfn.inet.stat.gateway.b1 = 168; itfn.inet.stat.gateway.b2 = 0; itfn.inet.stat.gateway.b3 = 1; itfn.inet.stat.dnsServer[0].address = "8.8.8.8"; itfn.inet.stat.dnsServer[1].address = "8.8.4.4"; itfn.selCfg = Interface.SC_AllowHotplug | Interface.SC_NoAutoDown; itfn.selCfg = Interface.SC_Auto | Interface.SC_NoScripts | Interface.SC_AllowHotplug; // ret = idItf.stopInterface(idItf.interfaces[2]); if(idItf.ifUpDownInProgress) idItf.cancelStartStopInterface(); else ret = idItf.restartInterface(idItf.interfaces[2]); // idItf.removeInterface(itfn); // idItf.saveAs("/home/wrk/share/gfanet/libgfanet/res/testitf"); } } }