前提条件:
1.路由配置dmz主机为tk1的ip ,设置路由器中ssh 端口22的访问权限
2.有一台远程服务器,服务器安装了php可以运行php文件(我使用的是阿里云)
家中tk1配置:
脚本python 部署在jetson tk1上,然后设置crontab 定时执行
把python脚本放在 /jetson/testip.py
crontab -e
*/10 * * * * /jetson/testip.py >>/dev/null 2>&1
/*———————-testip.py——————————-*/
#!/usr/bin/python
import re,httplib
conn = httplib.HTTPConnection("1111.ip138.com")
conn.request("GET", "/ic.asp")
r1 = conn.getresponse()
data1 = r1.read()
conn.close()
matchObj = re.search( r'(\d+)\.(\d+)\.(\d+)\.(\d+)', data1, re.M|re.I)
if matchObj:
ip=matchObj.group()
conn = httplib.HTTPConnection("remotedIP")
conn.request("GET", "/testip.php?debug="+ip)
r1 = conn.getresponse()
print r1.read()
conn.close()
else:
print "error"
2.远程服务器配置,直接在php网站目录下放下面php代码
/*————testip.php————–*/
<?php
$ipfile = "/var/log/homeip.txt";
if (isset($_GET['debug'])) {
$ip = $_GET['debug'];
preg_match_all('|\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}|', $ip, $out, PREG_PATTERN_ORDER);
if (!empty($out[0][0])) {
$ip = $out[0][0];
} else {
die();
}
$myfile = fopen($ipfile, "w") or die("Unable to open file!");
echo ($ip);
fwrite($myfile, $ip);
fclose($myfile);
die();
}
$myfile = fopen($ipfile, "r") or die("Unable to open file!");
echo fread($myfile, filesize($ipfile));
fclose($myfile);
die();
使用:
http://远程服务器ip/testip.php
返回得到家中jetson tk1 的公网地址,然后 ssh ip就可以登陆上家里的机器了
转载于:https://www.cnblogs.com/wyxy2005/p/4274467.html