diff --git a/README.md b/README.md index 6b772a4..2531a33 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # myip -返回本机的公网 IP 以及访问外网的 IP,使用 https://getip.pub 提供的服务。 +返回本机的公网 IP 以及访问外网的 IP,使用 http:/www.ip111.cn 提供的服务。 ```sh ╰─ $ bin/myip -国内网站:当前 IP:123.123.123.123 来自于:中国 北京 联通 -国外网站:1.2.3.4 -谷歌网站:1.2.3.4 +从国内测试:123.123.123.123 中国 北京市 +从国外测试:111.111.111.111 美国 洛杉矶 +从谷歌测试:111.111.111.111 美国 洛杉矶 ``` diff --git a/shard.yml b/shard.yml index fe75b45..a0e1fa7 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: myip -version: 0.1.0 +version: 0.3.0 authors: - Billy.Zheng diff --git a/src/myip.cr b/src/myip.cr index 491b66a..f85e90a 100644 --- a/src/myip.cr +++ b/src/myip.cr @@ -4,14 +4,13 @@ require "./myip/*" chan = Channel(Tuple(String, String)).new begin - doc = Crystagiri::HTML.from_url "https://getip.pub" + doc = Crystagiri::HTML.from_url "http://www.ip111.cn" iframe = doc.where_tag("iframe") do |tag| spawn do - title = tag.node.parent.try(&.parent).not_nil!.xpath_node("td").not_nil!.text url = tag.node.attributes["src"].content - ip = Crystagiri::HTML.from_url(url).content.chomp - + ip = Crystagiri::HTML.from_url(url).at_css("body").not_nil!.content + title = tag.node.parent.try(&.parent).try(&.parent).not_nil!.xpath_node("div[@class='card-header']").not_nil!.content.strip chan.send({title, ip}) rescue OpenSSL::SSL::Error STDERR.puts "visit #{url} failed" @@ -23,6 +22,11 @@ rescue Socket::Error | OpenSSL::SSL::Error exit end +title = doc.at_css(".card-header").not_nil!.content.strip +ip = doc.at_css(".card-body p").not_nil!.content.strip + +STDERR.puts "#{title}:#{ip}" + iframe.size.times do |i| select when value = chan.receive