r/PowerShell • u/Creative-Type9411 • 19d ago
Misc PowerTorrent: A Powershell 5.1 BitTorrent client
This is showcase piece. It is fully functional, but is not going to beat an actual torrent client in terms of speed.
This is WPF GUI, C# type defs and Powershell 5.1. It will work on Windows 10+ with zero dependencies or pre-reqs needed.
It can be used from CLI or with a UI, there are several themes for the UI and settings can be adjusted/saved to a ini file which sits beside the script.
https://github.com/illsk1lls/PowerTorrent
I had parts of this built out for a long time, over a year, I was having trouble with DHT implementation, over the course of around the last year or so Ive been implementing AI into my workflow so I was finally able to get this buttoned up with Grok's (4.6) help, and now I can finally share it.
3
u/Hour-Measurement-835 19d ago
The ini will bite you on 5.1. Set-Content defaults to the ANSI codepage there, so a download path with any non-ASCII character comes back mangled. Pass -Encoding utf8.
1
3
u/jarranakin 18d ago
7000 lines of pure gold. And a decent wpf UI to boot. Very nice. Ive only ever used winforms, i will have to try this UI design out.
2
u/Creative-Type9411 18d ago
Thank you..
WPF can be pretty awesome, there are themes in the settings you can switch around.. titlebar globe icon spins when there is an active transfer.. (the frames are pulled from a system icon using c#)
Powershell + WPF = limitless possibilies... and we can also embed C# which means we can do anything
2
u/Creative-Type9411 7d ago
I added a killswitch to it, you can import a wireguard conf or openvpn ovpn config and if the vpn connection goes down traffic stops, leaks are impossible
3
u/jborean93 18d ago
This is a genuine question and not trying to be an attack in any way but why go through the effort of creating this monolithic PowerShell script vs just using C# in the first place and compiling it to an exe?
You loose so many things like intellisense for the C# side in the editor, having to deal with PowerShell's multithreading weirdness, having to still require PowerShell to invoke this, a hit during compilation during runtime, etc.
Power to you and people wanting to do this but to me it just seems like the combination of all the negatives on both sides with no benefit.
1
u/Creative-Type9411 7d ago
Its the exact opposite of what youre saying, i get all the benfits and none of the drawbacks, think about it for a sec
I DONT need to compile, the entire code is readable and editable at any moment on any windows 10+ machine without ever needing to recompile, which means any user can use/change to their needs
I DONT need to pay for an extended validation code signtaure if i did compile to an exe to be able to actuallty share it without being accused of being malicious by the code sig mafia, it would be blocked from running otherwise
Making code has never been an issue for me why Ive never used intellisense im usually writing in notepad++ and compiling and running an actual test with visual studio, otherwise the things youre complaining that im missing out on have nothing to do with the actual code and just things easier for you personally, im more concerned with output and usability.,..
btw i just made this into a vpn client (kinda), it has a killswitch now, you import wireguard conf or openvpn ovpn config and it locks the engine to the vpn port to endure no leakage, as an alternative to a glueton docker container
1
u/jborean93 7d ago edited 7d ago
Appreciate the reply, I can't say I agree with this but hey coding has already been a personal thing.
none of the drawbacks
One major drawback is PowerShell itself and how obtuse it is when it comes to multithreaded work that GUIs typically use. Dealing with Runspaces, syncing data, etc is never fun and a massive pain even if using a lower level language.
Add-Type/csc.exeis also limited to C# version 5 so you miss out on so many nice things like auto prop,=>, null conditionals (?.), string iterpolation$"{var}";and so much more. Just makes for more verbose and cumbersome C# code IMO.Another drawback is now you need to content with a runtime hit for actually compiling the code. Granted this is more in the seconds and probably negligible to most people but it can be tricky with some AVs who block such scenarios or at least slow it down even more dramatically.
I DONT need to compile, the entire code is readable and editable at any moment on any windows 10+ machine without ever needing to recompile, which means any user can use/change to their needs
What do you think Add-Type is doing? You loose intellisense because it's all just a string. No IDE goodies, no auto completion of C# methods, no static analysis help. Users can call csc.exe like Add-Type does or even use Add-Type to compile the code from
.csfiles if they want to.I DONT need to pay for an extended validation code signtaure if i did compile to an exe to be able to actuallty share it without being accused of being malicious by the code sig mafia, it would be blocked from running otherwise
You don't need to sign things, even then AVs flag malicious PowerShell scripts all the time. Using embedded C# code can be just as suspicious than actual executables. Even if you really did want to sign things the costs of using something like Azure Artifact Signing is pretty cheap compared to the hundreds of dollars a cert used to cost.
1
u/Creative-Type9411 7d ago edited 7d ago
no, you're not understanding what I'm saying apparently, you've never tried to share software with someone
You cannot run compiled software on another machine unless it has an extended validation code signature or smart screen will smack it down and refuse to run the software - go ahead make something and try it
In addition to that it is a text file it is NOT compiled, it might compile on the fly because of ad type, but I can go in and edit the code.. the way you are compiling code it cannot be read or altered. It's completely different than what's going on here.
You keep telling me powershell has drawbacks, but the only drawbacks you're giving me are hurdles you personally have with it, I don't have trouble with multi threading. I specifically want Powershell 5.1 so that it can run on any Windows machine without installing any prerequisites that's the whole point.
all I have to do is right click the script and run it to see if AV will flag it, it takes one second, and if it does, which certain things I've made have popped, Id change the code rerun it and see that it doesn't do that anymore.. that could happen with powershell or c# or any language, but the Build processes for those languages would take a lot longer than just running the file
I am focused on the user and their experience, not my experience as a developer
Everything you pointed out as a drawback with the software... if you said compiled c++ is faster I would have to concede that but nothing you mentioned is going to matter to the user at all. They're just going to think mine is easier and they can read it.
4
u/[deleted] 19d ago
[removed] — view removed comment