I want to create program in C#.NET to limit network speed on all computers..any idea?
Not really possible as that would require you to write a new driver, as the .net framework is too high level to have access to such interfaces.
Sheng, if you would like to sniff what is on the network, you may be able to do it with C# and pinvoke, you can have a look here:
http://www.mentalis.org/soft/projects/pmon/
or at sys internals's TCPView just to get inspired...
Related
There are multiple network adapters of the same model in the target computer. As below, they are all Intel I211.
PCI\VEN_8086&DEV_1539&SUBSYS_00008086&REV_03\0060E0FFFF6336A000
Name: Intel(R) I211 Gigabit Network Connection
Hardware IDs:
PCI\VEN_8086&DEV_1539&SUBSYS_00008086&REV_03
PCI\VEN_8086&DEV_1539&SUBSYS_00008086
PCI\VEN_8086&DEV_1539&CC_020000
PCI\VEN_8086&DEV_1539&CC_0200
Compatible IDs:
PCI\VEN_8086&DEV_1539&REV_03
PCI\VEN_8086&DEV_1539
PCI\VEN_8086&CC_020000
PCI\VEN_8086&CC_0200
PCI\VEN_8086
PCI\CC_020000&DT_0
PCI\CC_020000
PCI\CC_0200&DT_0
PCI\CC_0200
PCI\VEN_8086&DEV_1539&SUBSYS_00008086&REV_03\0060E0FFFF6336A100
Name: Intel(R) I211 Gigabit Network Connection #2
Hardware IDs:
PCI\VEN_8086&DEV_1539&SUBSYS_00008086&REV_03
PCI\VEN_8086&DEV_1539&SUBSYS_00008086
PCI\VEN_8086&DEV_1539&CC_020000
PCI\VEN_8086&DEV_1539&CC_0200
Compatible IDs:
PCI\VEN_8086&DEV_1539&REV_03
PCI\VEN_8086&DEV_1539
PCI\VEN_8086&CC_020000
PCI\VEN_8086&CC_0200
PCI\VEN_8086
PCI\CC_020000&DT_0
PCI\CC_020000
PCI\CC_0200&DT_0
PCI\CC_0200
How do I update driver for a specific one of these same model adapters by devcon, C++ or C#? For example, update by the unique device instance ID (ex: PCI\VEN_8086&DEV_1539&SUBSYS_00008086&REV_03\0060E0FFFF6336A100)
Thanks
EDIT:
I've searched APIs for this but they all use hardware ID to update the driver, which will update all of the same model adapters' drivers.
Ex: C++'s UpdateDriverForPlugAndPlayDevicesA and devcon's update command.
EDIT2:
The motivation of this issue is that we are using an RTOS (real-time OS, RTX64) and we want to establish a real-time network communication (EtherCAT connection) with other devices by the RTOS. We need to update one of the adapters' driver to the driver provided by RTX64, so that this adapter can be used by it.
The only workable solution for us to just update one of them is using Windows' "Device Manager". (There's no same model adapters in the below picture, it's just shows how to update by device manager manually)
We are asking our users to do this manual update after installing our software. It's not convenient for them. So we are trying to find an automatic way to do this.
Since Device Manager in Windows can do this, we suppose that there's an API can do this too.
Two workarounds. One minimizes manual customer interaction when updating the device driver, the other fully automates the process, but requires coding in a BASIC like language.
The first one consists on automatically showing the Hardware Update Wizard for that particular device instance, using the API function DiShowUpdateDevice as described in the previous link.
The second one is to use the free AutoIt automation software. With it you can automate basically everything in a Windows system, it's very powerful and I've used it in conjunction with web bots and automatic web testing (non-headless). I've also used it in double-click roll-outs of Windows systems and many sysadmin tasks.
As a remark, you could also mix both approaches. First, use DiShowUpdateDevice to show the wizard and then an AutoIt script can automatically perform UI interaction, the client won't have to do anything at all.
This is not really a average Programmer Problem.
Driver Programming - as a subset of Realtime Programming - is a highly specialized field. The average C# or C++ .NET Programmer will rarely have to deal with stuff like pointers and neer with assembler level code. But for those two, it is their daily bread and butter. I can not give you little more then general advice:
My first advice for you is to get somebody elses code to make that decision and installation. Usually drivers of one Manufacturer are distributed in packages. Wich do understand how to deal with idenitifcation of the hardware. Usually those installers also have a silent mode. So it comes down to calling them and intercepting the console output/looking for the return value.
My second advice, is to use their name as listed in the Device Manager. Optionally get them renamed manually. It is not that reliable as strings are quite patient and easily changed/missmatched, but it would get you somewhere to start from.
But as I understand it your problem is worse then just general driver updates. You have two instances of the same Hardware, and want to use different drivers for each. Wich is a order worse:
I am not even sure this is possible. Since the driver folder still uses the good old "only one file of each name" approach, it is propable that you can not use different drivers for different instances of the same hardware. Unless you define your own driver storage location.
I have no idea why you would do that. The average enduser programm does not need to worry about even selecting wich interface it will use. It just hands it's request off the to network stack and does not deal with layer 3 or below. Servers may have to pick a specific adapter to listen on, or just listen on both in paralell. But even those do not care for the driver version in use. They do not even care if it is a real, physical interface - after all missclassification like with early Bluetooth and Virtual Devices like for Virtual Machine Monitors/PDF printers are a thing.
So it honestly sounds like you got a XY Problem, with this idea being the (propably wrong) Y, to your real X.
Actually I have three questions:
1- According to Nazar Grynko answer, Is it only intercepting the three functions(send , recv,and connect) will help me to anticipate all the packet in my machine?
2- If I hooked the three functions, How to get an IntPtr which points to a sockaddr structure from a P/Invoked native function?
3- Send, and recv are not having sockaddr, so how to figure out the addresses?
Thank you in advance.
The functions you described are a part of the POSIX standard. This means that when you use these functions on Windows, you're actually calling a wrapper that eventually translates to a system call. You can send packets without the use of this function (e.g, by using the Windows API).
See answer number one. This won't help you. You'd also have to provide a hook for all processes.
The functions you describe use a file descriptor which is a POSIX construct, and are user-mode simulated on other systems.
To inspect your traffic you must use a driver that will do it for you. You might want to look at Pcap.Net which is a C# project aimed exactly at your problem, and provides the driver and API necessary.
We have Siemens PLC S7-300 with Ethernet communication port.
Which type of java or other language coding available for getting the frame data of plc.?
this PLC communicate only with step-7 software.
This frame structure data also can store in xml of some text file so we can continuous send it to internet.
Please help me
There are 3rd party libraries that allow that. At our company we are using Accon AGLink. It's a native library, but it also provides a .NET wrapper. The library is somewhat fast. You could also try this one (indi.an PLCCom) which is managed, and not so fast, but it has a free version.
Alternatively you could try setting up an OPC server and read the PLC data using an OPC client, but they are somewhat expensive.
Have a look at Snap7, which is written in C but with many wrappers and ports available, including Python, Node.js, .NET, C#, Arduino, and one in Java called Moka7, since you asked.
From the official documentation:
Snap7 is an open source, 32/64 bit, multi-platform Ethernet communication suite for interfacing natively with Siemens S7 PLCs. The
new CPUs 1200/1500, the old S7200, the small LOGO 0BA7/0BA8 and SINAMICS Drives are also partially supported.
I'm assuming that your setup consists on an S7-300 CPU with a CP 343 communication module. To read data from the CPU, the system must be running an S7 server (configurable via NetPro, inside SIMATIC Manager, as explained in the Siemens commissioning manual). The remote machine should be using the Snap7 client library.
The library includes functions to read different memory areas, such as the process inputs (I), process outputs (Q), merkers (M), timers (T), and counters (C), as well as general purpose data blocks (DBs). If the server is enabled, and the configuration is not restricted (for instance to a certain IP address) the client should have access by default to at least the I's, Q's and M's, as well as to some system properties (like the CPU model and the firmware version).
For your case in Java, have a look at the Moka7 documentation, which can be found in the same download package. There are several code examples to get started.
If successful, the ReadArea function will return hex data of the bytes you specified (i.e. the memory position to start reading from, and the number of bytes). As a remark, remember that most Siemens PLCs are big-endian, so you may have to make a conversion if you're reading memory areas that hold data in different types.
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.
I have an update service that needs to pull data down from remote, however like Microsoft's BITS I'd like to do this when the user is idle and/or when their network utilisation is low so as to not impact on their experience.
What do I need to do or look at? Can anyone point me in the right direction on where to start with this and get the information I need?
Use official BITS wrapper http://msdn.microsoft.com/en-us/library/ms997639.aspx
How about SharpBITS.NET?
If you cannot use BITS because you want to be cross-platform, you're going to have trouble. Each OS will have different ways to find the current network usage, so you will have to write an interface class with implementations for each supported OS.
In Linux it seems to be the special file /proc/net/snmp. In Windows, BSD or OSX I have no idea. The netstat -s shell command seems to work on all of them, but the output format is different for each one.
Have you looked at MSDN where it describes how to use the BITS COM interfaces?
Another article here describing how to use BITS with .Net