Skip to content

Commit

Permalink
Use ip111.cn
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Sep 17, 2022
1 parent 2fee158 commit 1193a6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 美国 洛杉矶

```

Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: myip
version: 0.1.0
version: 0.3.0

authors:
- Billy.Zheng <[email protected]>
Expand Down
12 changes: 8 additions & 4 deletions src/myip.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 1193a6c

Please sign in to comment.