I am creating a .NET console application in C#. This application is a small script which uses the OpenVPN CLI to automatically connect to a VPN server without any manual steps.
I want to block all the network ports from the device, except the one which is being used by the OpenVPN CLI. E.g. port 1194. Can this be done in Windows and how could one achieve this? I tried something with the netshcommand by changing the default gateway of the system, but that resulted in a full internet block. E.g Process.Start with netsh interface ipv4 set address name="Wi-Fi 3" static 192.168.1.15 255.255.255.0 127.0.0.1.
I couldn't find a command/code to block all the ports except one, so any help in this would be appreciated.
Related
I'm developing a .NET MVC Application to query a PLC for inputs and outputs status using Snap7 library.
For development reasons I connect to my PLC (behind a router) using an SSH tunnel bound to a localhost port, so it becomes reachable at 127.0.0.1:102 address. In this scenario, everything works fine and I manage to read data from the device.
When I deploy my application to the production server a subtle problems begins: I'm no longer able to connect PLC. Error code from Snap7 library is cryptic and the only difference in code is the IP address (192.168.1.100:102 instead of localhost:102) so I suspect a permission problem is involved.
I'm searching for two solutions to my problems: one for the normal deployment, where I have full access to IIS Server and one for Azure deployment. I'm searching for something to put inside Web.config but I'm not still able to find suitable configurations or workarounds.
I have an UWP application which is connecting to a Socket.IO server. When debugging I like it to be a local server, but I can't get it to connect it. I use the SocketIoClientDotNet library, and it works well if I have to connect to an external server, but I can't connect to the local one.
I'm aware that on default UWP apps forbids connecting to local servers, I think it's called loopback, but I'm also tried to go around that by using this tool:
http://loopback.codeplex.com/
However, It didn't helped.
Any help is much appreciated, and thanks in advance! : )
I think the problem is that you didn't enable the relevant capability in your project. Please open the manifest of your app can select the Capabilities label and check the Private Networks (Client & Server) on the left.
This capability's name is "privateNetworkClientServe", this capability provides inbound and outbound access to home and work networks through the firewall.
For more info about capabilities, you can refer to App capability declarations.
Update:
Due to loopback restrictions enforced by network isolation policy, when use TCP protocol, server and client must run on separate machines for them to be able to communicate with each other.
I am trying to communicate with comms from a server to a client on the same PC. So if I send the word "Hello" from one it appears on the other like a chat program. As I am on one PC I set IP to 127.0.0.1 and port to 7000 although port could be lots of other numbers. When I press to connect it will not connect to local host.
On XP laptop all is OK so something in set-up is not good. I looked at opening Firefox and typed in Local Host it works, tried 127.0.0.1 it works so IIS is working BUT that is not what I want. I looked for files with local host in and find in C:\Windows\System32\drivers\etc a file called hosts with 127.0.0.1 and IPv6 version ::1 commented out. Uncommented and still nothing works.
Switched off firewall still no good, switched off Virus detection still nothing.
What have I missed how can a chat program talk on loopback in Win7?
I'm not sure if you are intentionally typing in Local Host separately. The host "localhost" is what you are after, followed by the appropriate port number.
Example:
http://localhost:7000/url_to_chat
If you have been doing that correctly, then you just need to define two different ports for each app if you are running both on the same machine in Windows 7 and done.
If you are using Visual Studio's IIS Express (recommended as you don't have to run as an admin), all you have to do is specify the port number and create the folder. You'll then have to run each app.
Hope that helps.
Try this site for information on how to change your hosts file:
https://bowerwebsolutions.com/how-to-edit-your-local-host-file-for-testing-web-sites/
I have an application that creates a HTTP server on a random port (50000-59000) on "localhost". It tries to connect to this port afterwards to determine if everything was setup correctly and is ready to use.
This seems to work on most machines very well. Its written in C#.NET 4.0 for Windows XP and higher.
Now I have the problem that on one server at one customer the creation of the server seems to work but it can't connect to it. Sadly we didn't any information as the exception details were not outputted from this software as it has happened.
It works if the file is on local disk. If they start it from a specific Windows network share it stops working. I think that the have a special setting which causes this issue. But I don't know that could be reason.
My Question:
Do you know settings, an system administrator could make, that prevents a software, running as normal user, to connect to a listening port, that the program has opened just a moment ago? May be group policy settings in the active directory?
I've written a test program to try this again at our customer.
running test on local host, the website coded with c#, is able to connect to the comm port and pass commands to the hardware just as done by hyperterminal software
if this website is uploaded/hosted this will not work, as the server doesnot have this harware connected to the comm port needed.
one way is to ask the hosting company to set up a special computer for me with the hardware drivers etc.
not possible.
defining hardware, the hardware is a remote control car.
so what is the solution?
You can create a Silverlight Out of Browser application which can run with elevated rights.
Perhaps it is possible to access the COM Port with ActiveX, too. But that would be a Internet Explorer only solution.
I found this blog where someone managed to get that working.
http://tech-michael.blogspot.com/2009/12/silverlight-talking-to-arduino.html