7
I need this down to as few characters as possible. I would use Test-NetConnection but I need PSv2 compatability. Any help would be appreciated.
$socket = new-object Net.Sockets.TcpClient
$socket.Connect("192.168.5.5",445)
$socket.Connected
As a note I have tried this but it doesn't work
(new-object Net.Sockets.TcpClient).Connect("192.168.5.5",445).Connected
1My code does work. I am proposing the challenge of "make it as few characters as possible". I fail to see how this is considered "off topic" when one of the topics is "programming challenges". Please explain.... – Michael Timmerman – 2017-04-03T17:20:19.027
5
@apsillers This is a perfectly on-topic question; we've accepted many "how can I make my code shorter" questions in the past: 1, 2, 3, 4, 5, 6, 7, 8, etc.
– ETHproductions – 2017-04-03T17:27:54.923This would be better suited for The Nineteenth Byte or something. IMO, it doesn't warrant its own question on the main site.
– Nick Clifford – 2017-04-03T17:28:25.7335
@NickClifford This type of question, while uncommon, is absolutely on topic.
– Martin Ender – 2017-04-03T17:30:01.987@NickClifford Viewed as a narrowly-applied
[tips]
question, rather than as a challenge, this is indeed on topic. (I say this as someone who originally voted to close the question.) – apsillers – 2017-04-03T17:33:31.837@apsillers Ah, I see. – Nick Clifford – 2017-04-03T17:34:36.133
1
OP, just to explain the contention here, the site accepts two types of posts: "challenges" to achieve some general goal ("Given a number as input, compute the lowest prime number higher than the input number" as one simple example) and "tips" which ask for help golfing in a particular language. "Tips" posts are comparatively rare, and are largely language-specific compendiums of knowledge (e.g., Tips for golfing in Windows PowerShell. However, tips-posts asking to golf a particular problem are allowed, but fairly uncommon, hence the confusion.
– apsillers – 2017-04-03T17:48:08.940