【问题标题】:Save the IP of a domain to a txt file/Save my dynamic ip to a txt file with c++ or batch将域的IP保存到txt文件/使用c++或批处理将我的动态ip保存到txt文件
【发布时间】:2012-12-23 06:25:32
【问题描述】:

^^^^

我需要将我的域 (xxx.noip.com) 的 IP 或我的外部 IP 保存到文本文件中。然后将其上传到公共保管箱帐户。

【问题讨论】:

  • 我的批处理和 c++ 知识水平最低。对不起,如果我没有留下任何例子或等等......
  • 打开一个文件,在里面写下你的IP,然后上传。
  • 自动?我有一个动态 IP,每 10 分钟左右更改一次
  • @user1924602 - 请将您的 cmets 合并到问题中,以使其更加具体和清晰。这将帮助您获得更好的答案。

标签: c++ networking batch-file ip hosts


【解决方案1】:

您可以通过浏览http://checkip.dyndns.org获取您的外部IP

假设您的 DropBox 文件夹是 C:\dropbox

这是一个批处理脚本,可将您的公共 ip 保存到您的保管箱文件夹中的文件中。

get_my_public_ip.bat:

wget -q -O - http://checkip.dyndns.org > C:\dropbox\my_public_ip.html

您需要wget 才能运行它,并且它应该放置在您的PATH 变量中的文件夹中(例如C:\Windows)。你可以找到一个windows端口here。 HTML 标记不会从文件中删除,因此其内容类似于:

<html><head><title>Current IP Check</title></head><body>Current IP Address: 1.2.3.4</body></html>

这是一个执行相同工作的 Windows PowerShell 脚本并删除不必要的文本。

get_my_public_ip.ps1:

(new-object System.Net.WebClient).DownloadString('http://checkip.dyndns.org')|% { $_ -replace '.*Current IP Address: ([0-9\.]+).*','$1' } > C:\dropbox\my_public_ip.txt

查看here 获取有关如何运行 Windows PowerShell 脚本的帮助。

希望对你有帮助

【讨论】:

    【解决方案2】:

    这是一个可以做到这一点的脚本。使用 cron 设置自动任务以更新 ip。

    #!/bin/bash
    # Script to write external ip to ip.txt in Dropbox folder
    curl icanhazip.com >> ~/Dropbox/ip.txt
    echo "The Ip for $HOSTNAME" >> ~/Dropbox/ip.txt
    date >> ~/Dropbox/ip.txt
    echo "" >> ~/Dropbox/ip.txt
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多