调整以太网络的设置

lowmem
Matthew 4 weeks ago
parent 514fc054a7
commit 789547b503

@ -0,0 +1,30 @@
#!/system/bin/sh
/system/bin/ip link set eth0 down
/system/bin/ip addr flush dev eth0
/system/bin/ip addr add 192.168.68.91/24 broadcast 192.168.68.255 dev eth0
/system/bin/ip link set eth0 up
/system/bin/sleep 1
/system/bin/ip route delete 192.168.68.0/24 table 20
/system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table 20
ADD_ROUTE_STATUS=$?
if [ $ADD_ROUTE_STATUS -eq 0 ]; then
echo "路由添加命令成功执行"
else
echo "路由添加命令失败,状态码: $ADD_ROUTE_STATUS"
exit $ADD_ROUTE_STATUS
fi
/system/bin/ip route flush cache
/system/bin/ip rule del to 192.168.68.0/24
/system/bin/ip rule add from all to 192.168.68.0/24 lookup 20 prio 1000
/system/bin/ip route flush cache
if /system/bin/ip rule | grep -q "192.168.68.0/24"; then
echo "路由配置成功"
exit 0
else
echo "路由配置失败"
exit 1
fi

@ -1613,10 +1613,10 @@ bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c
XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power ON");
std::shared_ptr<PowerControl> ethernetPowerCtrl = std::make_shared<EthernetPowerCtrl>(localPhotoInfo.closeDelayTime);
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
net_handle_t netHandle = 0;
#if ((!defined USING_N938) && (!defined USING_PTZ))
#if 0
// Wait about 10s
for (int idx = 0; idx < 84; idx++)
{
@ -1683,7 +1683,7 @@ bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c
// 2025-01-30
SetStaticIp();
}
std::this_thread::sleep_for(std::chrono::milliseconds(256));
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
std::string ip = GetIpStr(localPhotoInfo.ip);
std::unique_ptr<VendorCtrl> vendorCtrl(MakeVendorCtrl(localPhotoInfo.vendor, localPhotoInfo.channel, ip, localPhotoInfo.userName, localPhotoInfo.password, netHandle, false));

@ -271,6 +271,11 @@ public class MicroPhotoService extends Service {
try {
if (usingEthernet()) {
File ethShellFile = new File(getFilesDir(), "eth.sh");
FilesUtils.copyAssetsFile(getApplicationContext(), "eth.sh", ethShellFile.getAbsolutePath());
mConnectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] nws = mConnectivityManager.getAllNetworks();
@ -1174,11 +1179,7 @@ public class MicroPhotoService extends Service {
new Thread(new Runnable() {
@Override
public void run() {
if (getCustomAppId() == 2 || getCustomAppId() == 1) {
setStaticNetwork(iface, "192.168.68.91", "192.168.68.91", "192.168.68.0", 24);
} else {
setEthernetRoute(iface, "192.168.68.0", 24);
}
}
}).start();
@ -1918,20 +1919,53 @@ public class MicroPhotoService extends Service {
int exitValue = -1;
boolean success = false;
try {
File ethShellFile = new File(getFilesDir(), "eth.sh");
if (ethShellFile.exists()) {
Process process = Runtime.getRuntime().exec("/system/xbin/su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/sh " + ethShellFile.getAbsolutePath() + "\n");
os.writeBytes("exit\n"); // 重要退出su shell
os.flush();
exitValue = process.waitFor();
if (exitValue != 0) {
}
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line = null;
StringBuilder error = new StringBuilder();
while ((line = reader.readLine()) != null) {
error.append(line);
error.append("\n");
}
Log.e(TAG, error.toString());
} else {
Process process = Runtime.getRuntime().exec("/system/xbin/su root");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
// os.writeBytes("/system/bin/ip link set eth0 down\n");
os.writeBytes("/system/bin/ip link set eth0 down\n");
os.writeBytes("/system/bin/sleep 1\n"); // Add delay
os.writeBytes("/system/bin/ip addr flush dev eth0\n"); // Clear existing config
os.writeBytes("/system/bin/ip addr add 192.168.68.91/24 broadcast 192.168.68.255 dev eth0\n");
// os.writeBytes("/system/bin/ip link set eth0 up\n");
// os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20 2>/dev/null || true\n");
os.writeBytes("/system/bin/ip route replace 192.168.68.0/24 dev eth0 proto static scope link table 20\n");
os.writeBytes("/system/bin/ip link set eth0 up\n");
os.writeBytes("/system/bin/sleep 2\n");
os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20 2>/dev/null || true\n");
os.writeBytes("/system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table 20\n");
os.writeBytes("/system/bin/ip route flush cache\n");
// os.writeBytes("echo 'nameserver 8.8.8.8' > /etc/resolv.conf\n");
os.writeBytes("/system/bin/ip rule del to 192.168.68.0/24 2>/dev/null || true\n");
os.writeBytes("/system/bin/ip rule add from all to 192.168.68.0/24 lookup 20 prio 1000\n");
os.writeBytes("/system/bin/ip route flush cache\n");
// Verify routes were added
os.writeBytes("if ! /system/bin/ip rule | grep '192.168.68.0/24'; then\n");
os.writeBytes(" echo 'Route rule failed to apply, retrying...'\n");
os.writeBytes(" sleep 1\n");
os.writeBytes(" /system/bin/ip rule add from all to 192.168.68.0/24 lookup 20 prio 1000\n");
os.writeBytes(" /system/bin/ip route flush cache\n");
os.writeBytes("fi\n");
os.writeBytes("exit\n"); // 重要退出su shell
os.flush();
exitValue = process.waitFor();
@ -1981,8 +2015,9 @@ public class MicroPhotoService extends Service {
sleep(500);
}
if (exitValue != 0) {
}
} catch (Exception e) {
Log.e(TAG, "Failed to set interface down: " + e.getMessage());
}
@ -1995,6 +2030,7 @@ public class MicroPhotoService extends Service {
Process process = Runtime.getRuntime().exec("/system/xbin/su root");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/ip addr add 192.168.68.91/24 broadcast 192.168.68.255 dev eth0\n");
// os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20 2>/dev/null || true\n");
os.writeBytes("/system/bin/ip route replace 192.168.68.0/24 dev eth0 proto static scope link table 20\n");
os.writeBytes("/system/bin/ip route flush cache\n");

Loading…
Cancel
Save