Thursday, February 10, 2011

nslookup and dig in excel for mac

So, I cant program. I can babble perl, understand anything not c++ or ruby, and copy and paste. Oh, yes.

But need is the master of invention, and i had the need of report in an excel spreadsheet the IP address to which some domains and nodes would resolve, or not.

Easy, right?


common sense and time presure is saying to make cell B something like =nslookup(a1)
go scrolling down, and let the resolver do the job.
No such function or macro.

Looking in google show some visual basic crap, that requires windoze OLE objects (winsh, etc), but the, Applescript came to the rescue from some website. Changing the function for a shell objetc (dig +short xxx) made the trick, all the cells were nicely resolved down, in seconds.

Here is the Applescript code snippet:

on run

tell application "Microsoft Excel"

tell sheet "Sheet1" of workbook 1

set EndofRow to 333 -- This defines the last Excel Row with data; it this example, it is A333.

set input_data to ""

repeat with i from 1 to EndofRow -- This loop will run from row 1 until EndofRow set above. For this example, it was set to 333.

set InputCell to the value of (cell i of range ("A1:A" & i)) -- This line defines the range, where in this example it is set A1:A333 and i is the counter and will continue to loop until EndofRow.

set input_data to InputCell

set encoded_data to do shell script "dig +short " & input_data -- This is the resolver

set EncodedCell to ("B" & i) -- This is where to designate where the encoded data is to appear. In this example, the encoded data will be in Column "B".

set value of cell EncodedCell to encoded_data

end repeat

end tell

end tell

end run




And part of the final result (column c is "dig +short www.$domain):


Awesome!

#Leysinde

Under this hashtag, so many passions and dispair.

Spanish politicians (Who? I want all the names, remember January 9th) ignored common sense, civic duties and the people that voted and were claiming for their attention and voted for a law that, in the best case, wont change anything. It will give the actual cinema minister Sinde a nice job in a big company, after stepping out.

So sad, and silly. They will come, the net is where all things end up coming, and they won't be welcomed there.

So far, so good

So i had a blog long time ago, but did nothing with it. Blogs came and went, and today, "social" is the buzzword. Protocols have been superseded by applications owned by companies. Some oldies say they are just enhanced, distributes and graphical version of old Unix comands. I agree, the network os slowly unleashing the power of the Unix personal machine.

And I write this from a Mac, running some Unix flavour, not bsd, not sysv ... who remembers that? Who the hell cares.

Ah! ... last week IANA ran out of ipv4 addresses, gave the last slasheights to the regional registries and celebrated. Jon Postel didn't live to see it, I guess Joyce Reynolds was there. So ipv6, the poster boy of newfangled gurus is slowly coming to us.

So many things changed since the first post!

Looking back, I use tweeter now. Don't have the time to sit down and write. All the scribbled notes in paper never made it to the blog, so, the Blackberry with company paid flatrate connected me more, and allowed me to engage in connected activities while commuting. That's why tweeter makes it ideal, with the small keyboards on the run, to cry and publish those mental sparks.

Blogger got bought. So many did. Aw, anyway. Give it another run, so I can say I have been blogging since 2004, but had my 24 hours running linux box connected since 1995.