TCP/Telnet connection Winform to Winform c# - c#

I wish to simulate a connection between two forms in an application (it's a telephone network simulator).
I want to go beyond using simple methods to pretend there is a connection (IsEngaged(), IsConnected()) and somehow create an actual connection between the forms (telephones).
Am I correct in thinking I should be able to do this via telnet/tcp?
I'm not asking for a complete solution but would appreciate a nod in the right direction. All of my searches so far have come up with nothing similar to my scenario.
Many Thanks

I wouldn't bother with telnet - implementing Telnet is rather "hard work"...
For simulation purposes you can mock this with TCP or UDP or named pipe - anything usable for (bidirectional) IPC should work...

Related

c# - hiding a password for an SSH connection on a locally-run application

First of I'd like to say thanks to this community that has gotten me as far as I currently am programming in c#. I'm teaching myself as I go and not really doing any formal training so you guys have been a great help.
I'm writing a small application that is intended to make one of the mundane tasks for upgrading a piece of equipment my company sells a bit easier. Typically these devices are not connected to the internet, and we need to remote in to a customer's computer to accomplish the task of connecting to their device over SSH and running some commands once logged in to do the upgrade. I'm hoping to distribute an app to the customer, and an encrypted key (generated on our side) that has information about the options they are upgrading, and the serial number to ensure the key can only be used on their device.
In my app, I'm using SharpSSH to accomplish to initial SSH connection which is working great. However my concern is that the root password on our device is actually a fairly simple one. The devices themselves have rather limited functionality so not much someone could do if they got on it themselves, however if they got on the device they could upgrade theirs and anyone else's device if they so desired.
So my question is, how could I best 'hide' the password in my script so it's not easily searchable by anyone with a decomplier?
Right now the code is simply,
SshStream ssh = new SshStream(ip, "easytoguessuser", "notsocomplexpassword");
So I'd like to hide the password somewhere, but I can't think of a method that means someone with a decompiler couldn't just open up the exe and look for where the password is, or how I derive it from somtething else...
Like with real world locks you can't keep someone with the right tools out. You only can make it harder.
This can include:
store the password in an encrypted string that is only decrypted shortly before it is used
obfuscate the source code so it is harder to determine where the connection is initialized
This wont make it safe, but it hinders the less determined folks.

C# Create Dht Network(monotorrent dht lib)

So I wanted to add dht to my server and clients. And I looked into monotorrents. And it seemed straightforward but I'm wondering how I could make my own like sort of "torrent" to which all my clients can connect and then the servers that are connected are waiting for connections and the clients ping them to connect. So first i want to make 1 server a node in it already, and I thought I'd go with an infohash, but that didnt seem to work, if someone could just point me the direction? Sorry I'm really new in this p2p dht world. I did find a proper way to ensure that communication is really going where its intended to go, which was already hard for me
thanks in advance

Stream audio to several clients

I am making a website using ASP.NET and i have a webservice using WCF.
I need to figure out how i can stream audio(.mp3 files most likely) to several clients, so that all the clients hear the same, at the same time. I know this can be done using sockets, but I need a lot of different streams(which is not so good with sockets as i would need a new port to every stream, as far as know).
It is a kind of online radio-ish. Several channels, and users can then listen to the one they want.
Can anyone help me or point me in the right direction for something like this?
It does not have to be through WCF, I just need to figure out some way to do this
A quick way to get started with this is to just use SHOUTcast or Icecast.
They both work very similarly, providing an HTTP or HTTP-like server that streams MP3.

How do I get the ports opened by a Windows Service?

I want to get the list of window services and their ports in C#. I'm able to get all window services by using ServiceController but I'm unable to get ports of these services.
Please check this question on stackoverlow. It is not exactly the same as you are asking, but it points to a useful function called GetExtendedTcpTable available through PInvoke, that can do what you need. Also check this one.
After a lot of looking around I found that there's undocumented "OwningModuleInfo" in MIB_TCPROW_OWNER_MODULE structure.
Then looking for that I found this comment:
Weird issue regarding GetOwnerModuleFromTcpEntry when targeting x64
"I have reached the conclusion that the first item in the array is the index of the service in the list of running services, ..."
So the answer to the question would then be to use that to get name info that netstat -b shows (service name and address+port), filtering for your desired service. I found this https://github.com/Loriowar/IpHlpApidotnet lib which has bunch of related code already set up except for this feature.
Other useful links :
Marshalling Struct with Array of Struct Member
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366911(v=vs.85).aspx
The answers to similar questions always propose using Iphlpapi but it is not at all clear how would you get the RpcSs (service name) in this netstat -ban copy paste:
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
RpcSs
[svchost.exe]
Or the Schedule here:
TCP [::]:49154 [::]:0 LISTENING
Schedule
[svchost.exe]
I looked for solution to this and didn't find anything (-easy). Netstat calls into some undocumented functions in Iphlpapi but it's not clear whether it gets the service name from Iphlpapi or somehow uses the pid from Iphlpapi and uses something else to get the service name. I'm not really tempted spend time with a debugger to answer this because..:
However ideally one wouldn't want to use a polling-style approach from C# anyway. It would be more appropriate to use ETW. I think the lack of examples of using it from C# is because there's some overhead to getting started with it and examples around may be specific to other type of tracing/monitoring scenarios.
Summary: If you are short on time to implement this, just saving the netstat output seems to be the "solution". Ideally I would have liked to find a simple to use C# example to monitor any network connections and figuring out what service or process handled/initiated them along with possible firewall changes. I believe doing both is possible with ETW but for my current needs its hard to justify the unknown amount of time needed to get that working. I have atleast figured out that "logman query providers" lists the providers, then you need to do something to enable the provider (and driver support for tracing in some cases like packet capture). There's a C# project for using ETW around. But it's not at all clear how much effort it would be to reproduce the netstat output with ETW.

How to get socket ID/handle/descriptor for an already open connection? (.NET,C++,Delphi)

my question is stated in the title. How exactly do I do that?
I have an open connection and I want to "hijack" it and send my custom messages through it. From my understanding that is done with sockets and their handlers.
Any language would do but C#.NET is preferred.
Thank you
UPDATE: What exactly am I trying to achieve: I want to implement a keep-alive system for postgresql clients. That means get all the connections open to a postgresql database and every 5 minutes querying the database "select version()" to keep the connection alive. That's about it. It's for educational purposes mostly.
But I want to use this for any kind of connection.
Anyone? Ideas? Nothing? :(
This library: SharpPcap promises doing capturing, injecting, analyzing and building packets using any .NET language such as C# and VB.NET (more info)
It is the library used by Wireshark and it is for sure that it can capture and analyze.

Categories

Resources