doutang0335 2019-07-09 12:40
浏览 100

如何将我的ISP租用IP提供给LAN?

I have a dynamic IP address, changes every time my router is restarted. I have complete access to my router. What I do every morning is manually execute this script from terminal to get the new updated leased IP. Lease time is about a week if we don't turn off the router. I have to check everyday for new IP. Our LAN's workstations need to use the leased external IP in order for their software to work right.

I have setup two separate php scripts

1) A plain file that contains the value of the actual ip.php

<?php
$ip="200.121.215.117";
?>

2) A middleware script that evaluates if leased external IP has changed:

<?php
include 'ip.php';
$oldip = $ip;
$newip = $_SERVER['REMOTE_ADDR'];
echo "Old IP : ".$oldip. " & Current IP : ". $newip;
if ($oldip <> $newip) {
    echo "<br>Different IP found, updating workstations IPs done...<br>";
    unlink('ip.php');   
    $file = "ip.php";
    $a = fopen($file, "a");
    fwrite($a,"<?php"."
");
    fwrite($a,"$"."ip=\"".$newip."\";
");
    fwrite($a,"?>"."
");
    fclose($a);
    $a = fopen($file, "r");
    fclose($a);
    echo "<br> Set IP to :\"".$newip."\"
";    
} else ($oldip == $newip) {
    echo "<br>Same IP, nothing done";
} 
?>

3) And finally access the IP as a text from any LAN workstation

include '/home/myweb/public_html/ip.php';
echo "IP=".$ip;

I was thinking on executing this script directly on the router via cron setup unless someone has a better and more efficient way to do it.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算