last day (15 days later) » 

5:59 PM
1
A: Powershell converting IP's to resolved DNS - Export to Excel

TheMadTechnicianNot going to try and put this in a comment. I'm not sure why you changed those lines from what we had done before: $DNSWithKeyword = $DNSResults | ?{$_.HostName -match $Filter} $DNSNoKeyword = $DNSResults | ?{!($_.HostName -match $Filter) -and !([string]::IsNullOrEmpty($_.HostName))} $DNSLookupF...

 
Beacause now the results for DNSWithKeyword come out as: HostName Aliases AddressList -------- ------- ----------- cf-173-245-51-69.cloudflare.com {} {173.245.51.69}
Maybe it has something to do with the PSCustomObjects?
I basically tried the Clip cmdlet this time, because I noticed after scheduling it with your previous solution it didn't work as well, just tried something different I also set all involved COM objects to run as same user I also Tried setting all COM objects to launcing user And back to normal... All to no avail.
 
According to the script you posted I don't know how it responds with the properties 'HostName', 'Aliases', 'AddressList'
 
That's exactly the thing. Using your option it doesn't use the right properties and the output is buggered. It should be Source Hostname IPAddress That is what it also uses when using the script posing above. The script from last post did not, if you can recall and you told me it might be something i could do by myself... well, this is what I came up with... :P All I can think of now is maybe the PSCustomobjects..
 
Try those, at the very least they're the right operators in general for what you're trying to do.
 
I did, and the results are the ones I need. However the output is in incorrect format... As an example of the format look here: 149.210.173.203/BlockedIp/HTML/2014-08-20(1)/IP-2014-08-20.htm This is the result of the suggestions you gave me. Whilt is should be something like this: 149.210.173.203/BlockedIp/HTML/2014-08-20/IP-2014-08-20.htm
On your edit; The first 2 categporys are working like a charm. The last one is still showing a buggered result. (Hostname - Aliases-AddressList) Thanks already for your help
$DNSResults | ?{!($_.HostName -match $Filter) -and !([string]::IsNullOrEmpty($_.IPAddress))} Seems to do the trick: (Source - Hostname - IPAddress output) However, it is not the correct property... >.< But it does do the trick! :-)
 
5:59 PM
Try what I just posted and see if it works for you. I think I worked out the kinks, but you may have to check for null IPAddress like you suggested.
 
Indeed had to alter the last category a little, but it is working nicely now. Also the regex you created is much more efficient, thanks! :D The script is now really usable, just wish the final bits of polishing could be realized I also edited my question
 
Categories 2 issue addressed.
 
Legendary on the adding property's, learned something new again. :-) Why dont you post your awnsers in several columns? = more creds :P + could you explain a little more on how that function works? I rly like it.
Nvm, on closer inspection it makes complete sense, apart from the custom objects, im still not that familiar with it. You also helped me with the regex thingy btw :P
Hey there! :-)
 
6:10 PM
hello there
I was just looking into making IPs into links, since you already had the code in there to set hyperlinks it should be pretty easy.
Add this line just before you save the file:
$c.usedrange.cells | Where{$_.Value2 -match "(\b(?:(?: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]?)\b)"} | ForEach{$IPLink = "http://$($Matches[1])";[void]$c.Hyperlinks.Add($_, $IPLink)}
that will turn a cell with 141.32.105.18 into a hyperlink to 141.32.105.18
and the chat engine actually converted that. the second version actually should have http:// on it
it only matches valid IP addresses, so in the sample list you gave it set a hyperlink to everything except 111.111.311.25 because that's not a valid IP
 
Nono but the link should be http-://who.is/*ipnumber in question*
Its a nice touch though :-)
 
that's easy enough to change. Just replace "http://" with "http-://who.is/" and you're set
 
Duh.... >.< *feels stupid*

Will this be the same clumn as the IP stated or the secondary one?
 
that looks at every used cell on the sheet
 
Awesome. :D
Hmm it only ran on 4 IP's out of 60
... :-/
 
6:25 PM
if you want only specific cells you could give it a range and it'll only affect that range. you just change the first part ($c.usedrange.cells)
 
That last option would be faster :P
 
hm, only 4 out of 60? I ran it on the test data with the last script I posted in my answer and it seriously worked on all but the one
 
Sadly it doenst here...
254.254.254.254
83.163.219.209
64.39.103.235
3 actually... >.<
 
those are what it did work on?
 
6:28 PM
what's one that it didn't work ok?
on*
 
108.162.254.116
141.101.105.12
141.101.105.121
141.101.105.14
141.101.105.15
141.101.105.170
199.27.128.103
173.245.53.70
173.245.53.137
173.245.53.121
173.245.53.104
173.245.53.103
173.245.51.69

IP's not in whitelist
64.39.103.235
64.39.103.176
62.234.14.9
93.232.254.168
84.148.115.131
127.0.0.1
88.74.189.168
83.163.219.209

IP's without DNS return
46.19.33.143
254.254.254.254
111.111.311.25
0.0.0.0
- the 3...

It copied the whole sheet... wow
Oh and it's 30
Thought i picked a bigger list... :-)
So 3 out of 30 worked
 
wow, um, that doesn't make sense to me. I seriously have at least some of those in my list that it did work on.
 
:(
Im gonna light up a thinking rod... :P
Brb
 
so I just copied that list, and pasted it into my spreadsheet. Then I ran that one line of code and it hyperlinked all except the one bad IP again.
When you get back can you update your question with your current code?
 
6:45 PM
Sure
Done
I just ran it again, looks like it just skips a whole bunch of IP's
Could you explain the 2 lines of script you just provided?
Because basically it should just look at numers like: 1..255.1..255.1..255.1..255
 
that should all be 1 line, and yes, it looks for 0-255.0-255.0-255.0-255
 
It should be a 1 liner?
 
yes it should
 
But it is with the | right?
 
everything from $c to $IPLink)} all on one line
 
6:57 PM
[void]$c.Hyperlinks.Add($_, $IPLink)} that part?
 
Which one? d'oh
 
$c.usedrange.cells | Where{ all the way to $IPLink)}
 
Just did it, to no avail

Powershell already sees it as 1 line due to the pipeline symbol
 
ah, yes, it allows line breaks after a pipe
 
6:59 PM
;-)
Yay i made a smart comment xD
What version you using? I am using 4 on this server
Also, maybe i am missing something?

Where is $Matches coming from?
 
that is automatically generated from the -Match statement in the Where clause
I'm using PowerShell v4 as well
 
Kewl, just learned something :)
 
the fact that it works for some, but not all confuses me.
 
it is rather dubious
 
I don't think it will make a difference but it can't hurt... try changing your $D | to $D.cells |
if that fixes it I'll be amazed, but it can't hurt
 
7:13 PM
Tried already :P
Even tried specifying the range that was most important
 
7:26 PM
Still going over your code to see if there's anything in it that would cause differences from mine.
might I suggest a change:
$Keywords = @("Google","Cloudflare","Cloud","Ping",
"Easy-Voyage","McAfee","Pingdom","Panopta","Scoot","Uniglobe",
"Internal")
backticks are easy to miss, and if you accidentally have a space after it or something it breaks the script
When you define an array with the @( and ) you can have linebreaks after any comma
Ok, using your code it only set 1 IP with a hyperlink. WTF
 
Lol
Will use your suggestion, personally i am used to the backticks
 
it's really not so much for you, as it is for anybody else who has to deal with the script later on
 
True dat :-)
Hey u changed the code also
I have here:
$Keywords = "Google","Cloudflare","Cloud","Ping", `
"Easy-Voyage","McAfee","Pingdom","Panopta","Scoot","Uniglobe", `
"Internal"
 
As awesome as your script may end up being, something will eventually break it
 
I am getting really fond of the results :P
A lot due to your help :P
Ah i get the change.. :)
Btw:
$DNSNoKeyword = $DNSResults |
?{!($_.HostName -match $Filter) -and !([string]::IsNullOrEmpty($_.IPAddress))}

Ended up being the successor
I think it's because i am addressing 2 values
 
7:41 PM
it's your RegEx to match IPs. I don't know why, but that's the problem
Um, it's a horribly long and obnoxious string, but try erasing it and typing it in by hand
 
{$_.Source -Match "(108.162.254|141.101.(?:104|105)|199.27.128|173.245(?:53|52|51))"}{$_.HostName = "CloudFlare, Inc."}
{$_.Source -Match "(64.18.[0-18])"}{$_.HostName = "Google, Inc."}
{$_.Source -Match "(192.168|127.0.0)"}{$_.HostName = "Internal Infrastructure"}
Those?
Oh heavens...
Why does it have anything to do with that? :O
 
it's got something to do with the copy/paste I think. You must be getting a character that's an alternate or something
it's the long one, at the end before the save
 
I don't know, I copied and pasted your script and it didn't work. it's broken just like on your end
 
Maybe Ill copy it to a txt file
then copy it back?
Think it'll help?
 
7:44 PM
when I ran it against $a.activesheet.usedrange.item(26).value2 it failed to match, but when I copied and pasted my original in there it did match
but I don't see any difference in the two, it's bizzar
you can try
 
Notepad:
$NoDNSRange | Where{$_.Value2 -match "(\b(?:(?: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]?)\b)"} |
ForEach{$IPLink = "http://who.is/whois/$($Matches[1])";[void]$c.Hyperlinks.Add($_, $IPLink)}
Nope...
$NoDNSRange.cells neither
Arg... just for the sake of science i am going to re-type it
:P
Or what about pasting your code in your awnser sheet?
For the sake i am going to start typing now lol
 
added it to my answer
 
TADAAAA!!!!
Legendary.
For the sake of everything good in the world, do not copy/paste code in this chat... lol
 
it probably would have been ok if I'd flagged it as code (put a backtick before and after it)
 
Ah :P
Thanks man, ur great! :D
 
7:51 PM
looks like there's still some formatting issues, like cell alignment
you're welcome
 
Cell alignment?
Whatcha mean?
 
things lining up with the left vs right side of the cell
 
Everything lines up right, right? :P
 
on my spreadsheet 111.111.311.25 and 0.0.0.0 are both left justified
 
Peculiar, here it doesnt :P
 
7:53 PM
so is column C for those entries
 
All aligning fine here... :P
strange... But I am very satisfied! :D
 
that's what counts
 
;-)
Just 1 problem left...
Correction, 2.
1 minor, 1 annoying
 
the paste issue is the main problem really
 
yea
I dont 'mind' running the script manually that much
But it would be a lot nicer to schedule it
 
7:55 PM
so, I guess my next question is, does it not copy, or does it not paste?
when you schedule it to run, are you running it as your account?
 
It does copy, but doesnt paste the info into the sheet
Ran it under several accounts
Current user, system, administrator
Tried setting scheduled user as admin
And the involved COM objects to run under administrator *As example*
 
ok... how do you know it copies? are you able to paste into something else? My only other thought on it would require a major re-write. Generate a CSV file, open that in Excel, and apply formatting afterwards.
 
To no avail
Gah... re-write...
 
yeah, I wouldn't be real wild about that thought if I'd put this much time into a project either.
 
well no i am not 100% positive it actually copies, but it should... :P
The only thing i could think of is that the task manager itself keeps the clip info
so that the powershell.exe is ran as Admin
But task manager itself keeps the clip info
I had been thinking about re-write... but simple 1

Instead of using clip, blurt it to 3 seperate csvs, that excel imports
But im not crazy about the idea
And to be honest, this script is already a million and 1 times better then the previous 'solution' my employer had for me...
Gah just imagine...

You get a mailbox, that gets an average of 200 Blocked IP messages a day
In that mail there's a header,
Some more text,
The IP in question, with some text attached to it...

Then you have to copy that ip, without the rest of the text
Then you have to go to www.who.is/whois/ipaddress
Look if it's good or not...

Then loop.
Let me tell you, It was mind numbing and I felt so... Frustrated
lol
 
8:04 PM
yeah, I can understand that. talk about mindless work
 
Indeed...

Oh well, that's in the past now, and I already received kudo's for this initiative... :P
My collegue just realeased a monster
Ill brb
The coast is clear... :P
 
8:35 PM
You know, this copy/paste thing may be worth creating a separate question on SO for. Something specific, with a descriptive title, and maybe somebody more knowledgeable will chime in.
 
Yeah perhaps you're right
Hey but why dont you seperate your awnsers? then I can flag them all as positive :P
However, You've been a legendary help once more, thanks man!
Appreciate it. A lot. :-)
 
meh, not worth the effort of splitting them out. another 10 or 20 points isn't that big of a deal I don't think.
and you're quite welcome
 
:D
Cant wait to show the results of the script to the rest of the team, they gonna be happy like that guy from the happy song :P
 
If I drop out of the top 1% of people on SO maybe then I'll worry about skimming rep where I can
man, they better be. You've put a lot of work into that thing
 
Hehe, well to be honest I am not sure how long it wouldve taken me without your help... :P

But yeah, they better be :P
Gonna save people 1 - 2 hours a day, at least.

On to the next project! :-)
Thanks dude! I'ma run now.

See ya soon, maybe(?)
-Cheers!
 

last day (15 days later) »