![]() |
|
[Shell] [PowerShell] TCP Port Listener - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Shell] [PowerShell] TCP Port Listener (/showthread.php?tid=5693808) |
[PowerShell] TCP Port Listener - Travelers - Aug 13, 2017 To start off, this script is not what you are thinking it is. This was just something I coded up to double check that ports were open on some servers/client systems that I manage. I didn't really need to make this, but it was a lot of fun trying to get it to work. You learn more by finding a problem and then trying to code a solution. Code # to start listener Listener.start();Now, this little guy, when called, will listen on whatever port you designated. It will holed at the $listener.AcceptTCPClient() method until something makes a connection on that port, as it is awaiting traffic. I left the code in the comments for the command to run on the remote system (or vice versa) to connect on the port you are listening. It should return something to the effect of this, if it was successful. Code Client : System.Net.Sockets.SocketYour focus here should be the "Connected : True" statement, showing you that the connection was successful (true). Feedback and questions always welcome. 🤝 * - HFDone - Aug 13, 2017 ... $listener.AcceptTCPclient() $listener.stop(); WHY TOU CLOSE IT ? * - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - Aug 13, 2017 Can you please explain to me this? Code $port = [int]$inputIt seems you're giving port a value, but why all of these $? It's either built into the language itself, or OP is subtly telling us he's "ballin" * - HFDone - Aug 13, 2017 (Aug 13, 2017 02:38 PM)ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ Wrote: Can you please explain to me this? the $ symbol in PS is to declare vars so he declare port as integer * - Travelers - Aug 13, 2017 (Aug 13, 2017 02:01 PM)HFDone Wrote: ... You close it because after you establish a connection, there's no need to leave it open. This is just a test to check if a port status is up or down, not a l33t h4x0r tool. (Aug 13, 2017 02:38 PM)ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ Wrote: Can you please explain to me this? Yes, the $ symbol in PowerShell is to define a variable. The reason this line is coded as so is because when we take the value of $input from the user, it is read as a string and must be passed to the listener as an integer. Placing [int] in front of the variable $input converts it from a string to an integer and stores it in the $port variable. Does that make sense? * - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - Aug 13, 2017 (Aug 13, 2017 03:11 PM)Travelers Wrote: You close it because after you establish a connection, there's no need to leave it open. This is just a test to check if a port status is up or down, not a l33t h4x0r tool. Yes it does! Thank you very much for your explaination. And thanks to HFDone as well for another good question. I also was wondering the same thing! So I've learned a lot from this thread so far. Travelers, you don't know it yet, but you're going to be teaching me PS if you keep releasing (ya know, with all my questions). * - Travelers - Aug 13, 2017 (Aug 13, 2017 04:34 PM)ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ Wrote: Yes it does! Thank you very much for your explaination. And thanks to HFDone as well for another good question. I also was wondering the same thing! So I've learned a lot from this thread so far. Travelers, you don't know it yet, but you're going to be teaching me PS if you keep releasing (ya know, with all my questions). Haha. No worries, dude. Maybe one day I can make something a little bit better. For now though, these little scripts are all I've got. |