morrislaptop Posted January 8, 2014 Posted January 8, 2014 Quickly get the IP address for a host. Useful for debugging where a host is pointing to according to hosts file or DNS. Download from Dropbox
ebarrere Posted February 10, 2014 Posted February 10, 2014 Nice. I almost wrote one of these today, but you did it for me Cheers.
Don Dahl Posted August 1, 2014 Posted August 1, 2014 Link doesn't work anymore. Anybody up for a fix? I don't know workflow OP posted supports http:// input as well but it'd be nice to have. Another feature that'd be nice is reverse lookup. I mean, if an ip is specified then output the hostname for that ip. A friendly soul out there? Thanks a lot
Helmi Posted March 8, 2015 Posted March 8, 2015 Damn not online anymore - would really need such a tool. Probably easy to build, ha? Any hints?
rice.shawn Posted March 8, 2015 Posted March 8, 2015 Damn not online anymore - would really need such a tool. Probably easy to build, ha? Any hints? Find a whois service that has a public API that you can use. Then, pick your language (probably PHP, Python, or Ruby because of their ability to handle the probably JSON that the API will send back), and wire up the appropriate Alfred library. Adding in some URL validation would probably help.
rice.shawn Posted March 8, 2015 Posted March 8, 2015 Actually, nevermind. Use wrap the command around `ping` or something else that gives you the output.
rice.shawn Posted March 8, 2015 Posted March 8, 2015 Two options: nslookup "{query}"|grep Address:|grep -v \#|head -n 1|sed 's|Address: ||g' or ping -c 1 "{query}"|grep PING|sed -E 's|.*\(([0-9.]*)\).*|\1|g' "{query}" is obviously the website to look up. The output for both commands will be the IP address. Caveat: if you try this with a bad host (my test case was the word "cheese"), then you get an IP for the nslookup, but with ping you get "ping: cannot resolve cheese: Unknown host"
bcc2k Posted March 12, 2015 Posted March 12, 2015 Or, you could get the awesome workflow from daenishe instead: http://www.packal.org/workflow/resolve-url
deanishe Posted March 12, 2015 Posted March 12, 2015 (edited) Or, you could get the awesome workflow from daenishe instead: http://www.packal.org/workflow/resolve-url Thanks, Andreas That only works with URLs (i.e. webservers), not arbitrary hostnames. However, the relevant Python code from that workflow is: import socket def dns_info(hostname): """Return DNS info for hostname""" try: host, aliases, ipaddrs = socket.gethostbyname_ex(hostname) except Exception as err: print('Error fetching DNS for {} : {}'.format(hostname, err)) raise return { 'hostname': host, 'aliases': aliases, 'ipaddrs': ipaddrs } Example output: >>> dns_info('www.google.com') {u'ipaddrs': ['74.125.136.106', '74.125.136.105', '74.125.136.103', '74.125.136.147', '74.125.136.99', '74.125.136.104'], u'hostname': 'www.google.com', u'aliases': []} >>> dns_info('www.yahoo.com') {u'ipaddrs': ['46.228.47.114', '46.228.47.115'], u'hostname': 'fd-fp3.wg1.b.yahoo.com', u'aliases': ['www.yahoo.com']} Edited March 12, 2015 by deanishe
erist Posted March 17, 2015 Posted March 17, 2015 I whipped up a quick workflow that can go in both directions. My first workflow Check it out and let me know what you think. http://www.packal.org/workflow/web-ip-address
deanishe Posted March 17, 2015 Posted March 17, 2015 What does the IP lookup do? I've tried it with a couple of my IP addresses and it just gives me the same IP address back…
erist Posted March 17, 2015 Posted March 17, 2015 hmmm, could you send a screenshot? On my system `ip domainname.com` gives a list of all IP addresses that that domain name resolves to, like so http://cl.ly/image/2g3T0J1f2A1o and the reverse gives the exact server that an ip address points to http://cl.ly/image/1X3v3H2y3M17
erist Posted March 17, 2015 Posted March 17, 2015 perhaps I should include a regex that offers better feedback - `ip` is for looking up the numerical ip address of a domain. `whois` is for looking up the server name of a numerical ip address.
deanishe Posted March 17, 2015 Posted March 17, 2015 Don't worry, just ignore me. Because you said "both ways" and I'm used to calling whois with a hostname, I got it into my head that the ip keyword was a reverse DNS lookup that wanted an IP address as input, not a hostname.
rice.shawn Posted March 17, 2015 Posted March 17, 2015 You could also just use a single script filter to route it in case the user does what Dean does and (un)intentionally breaks it. So, here's some untested Ruby code: query = ARGV[0].downcase if ARGV.length > 0 query.strip! if /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/.match(query) /usr/bin/ruby __dir__/ip_lookup.rb query else /usr/bin/ruby __dir__/whois.rb query end Or, you could use a more complex regex that actually checks to make sure that the ip is in range: query = ARGV[0].downcase if ARGV.length > 0 query.strip! regex = RegEx.compile('^(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)^(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$#46;){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$') if query.match regex /usr/bin/ruby __dir__/ip_lookup.rb query else /usr/bin/ruby __dir__/whois.rb query end But, you should double-check these because they're untested (and because my head hasn't been in Ruby recently). But the logic is solid: check if the user is inputting an IP address; if so, use the ip script; if not, use the whois script.
erist Posted March 17, 2015 Posted March 17, 2015 thanks all, I will likely implement something like that. I agree whois was a bad choice for a keyword, given that it has other connotations
erist Posted March 17, 2015 Posted March 17, 2015 Mainly this was made to learn how alfred workflows work, but someone seemed to want the domain name to ip address functionality so...
deanishe Posted March 17, 2015 Posted March 17, 2015 Does anyone know if there's any way to get all the hostnames/subdomains/domains that map to a single IP address? Or can you only get the rDNS hostname?
rice.shawn Posted March 17, 2015 Posted March 17, 2015 Mainly this was made to learn how alfred workflows work, but someone seemed to want the domain name to ip address functionality so... That's how we all start. It seems that the most common development pattern, for simple workflows, is to throw everything into a single script filter, and one that does more to guess what the user wants. Having as few keywords is a good thing to do, especially when people start installing 100+ workflows (like me..., and Dean), so that there are fewer to remember. Really complex ones (think the Evernote workflow, the Spotify Workflows, ZotQuery) have multiple ones for really good reasons. Does anyone know if there's any way to get all the hostnames/subdomains/domains that map to a single IP address? Or can you only get the rDNS hostname? There is no straightforward tool to do so, but it looks like you can find something with Robtex.com. Check out this example (https://www.robtex.com/en/advisory/ip/162/243/215/240/), which is a redirect for (https://www.robtex.com/ip/162.243.215.240). There's also an API, but I haven't looked into it too much.
rice.shawn Posted March 17, 2015 Posted March 17, 2015 Does anyone know if there's any way to get all the hostnames/subdomains/domains that map to a single IP address? Or can you only get the rDNS hostname? The Robtex thing doesn't really show subdomains. But, I guess that you could try to get more information by finding starting with Robtex and then finding and parsing the zone file for each of those domains...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now