How can I find my Internet Service Provider (ISP) using a bash script?

You could use e.g. the services of ipinfo.io to determine your public IP including some additional information like the provider company name.

The site can be normally visited in your browser, but if you query it from the command-line with e.g. curl, they respond in a clean and well-defined JSON format so that you don't need to parse any HTML:

$ curl ipinfo.io
{
  "ip": "xxx.xxx.xxx.xxx",
  "hostname": "xxxxxxxxxxxxxxxxxxxxxxxxxxx.xx",
  "city": "xxxxxxxx",
  "region": "xxxxxxxxxx",
  "country": "xx",
  "loc": "xxx.xxxx,xxx.xxxx",
  "org": "xxxxxxxxxxxx",
  "postal": "xxxxx"
}

To only show one value, you can directly send a request to the respective path. E.g. for the ISP name (org), try this:

curl ipinfo.io/org

Inspired by this answer.


You can use many websites, that provided to to find your ISP name. One of them is whoismyisp.

And for get your ISP name, in bash script you can get this site by something like curl.

curl -s https://www.whoismyisp.org | grep -oP -m1 '(?<=isp">).*(?=</p)'

Also you can find ISP of any desired IPs with this command:

curl -s https://www.whoismyisp.org/ip/xxx.xxx.xxx.xxx | grep -oP -m1 '(?<=isp">).*(?=</p)'

Thats xxx.xxx.xxx.xxx is that IP you want to find its ISP.


Additional information: You can find your IP by bash with this command (thats may be helpful for scripts):

dig +short myip.opendns.com @resolver1.opendns.com

Tags:

Bash

Scripts