Identify type of devices in an IT Environment using C# (i.e. Windows, Linux, Network etc) - visual-studio

I have to scan my Infrastructure and find it out the way I should use (WMI, SSH, SNMP, etc.) to discover the device details.
The approach I am following as of now is
Get the availability of device.
Query using WMI (If responding? use this protocol to discover this device)
If the above device does not respond to WMI use another protocol like SSH or SNMP (it's configurable) etc.
Is there any other way of discovery for a mixed environment? Please suggest.

The approach you are taking seems reasonable. Alternatively, you could have some existing software do this for you.

Related

How do I implement per-app routing behavior on windows?

I am running a VPN in windows 10 desktop (using OpenVPN) and the VPN is the default gateway, so that all traffic by default goes through the VPN tunnel.
However, I would like to exempt certain apps from the VPN, so that their traffic goes directly out the physical interface instead, by passing the VPN (so-called "split tunnelling")
I assume this solution would involve the WFP (Windows Filtering Platform) API, and perhaps the Windows equivalent of
setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, device, sizeof(device))
I have this working in Linux currently via "cgroups" and policy-based routing/multiple routing tables.
But it is my understanding that Windows has neither policy based routing or multiple routing tables. But i can still think of a way of achieving this in Windows, but I cannot find the APIs to make it happen
One way is to hook the socket creation of a specific app and then use the windows equivalent of SO_BINDTO_DEVICE socket option (setsockopt()) to force the socket to be bound to the physical interface rather than the tap driver.
But, again, I cannot find the relevant APIs to make the above happen.
So I have a few questions:
(1) Is what i want to do possible within the given APIs of WFP (Windows Filtering Platform) or Windows APIs in genral? if so, which APIs do you advise i look at?
(2) Or, must i write a "WFP call-out driver" ? If so, would you be able to point me towards some resources for this, and possibility a good starting point for my particular problem? :)
(3) Is there anything else I might be missing? a simpler approach to achieve what i want? I know that it is possible in windows, as i have see the feature in some VPNs, but i would like to replicate it in my own personal VPN :)
Yes, you can force an app to use your VPN connection by copying and editing your (Windows) VPN connection.
Open the run prompt with: WIN+R
Type: ncpa.cpl
Copy your "old VPN" to APP_VPN (for example)
Open a Normal user Powershell
Change the new VPN connection with:
Add-VpnConnectionTriggerApplication -Name "APP_VPN" –ApplicationID "C:\path-to-your\game.exe" -Force
# Enable (Application) split-tunneling
Set-VpnConnection -Name "APP_VPN" -SplitTunneling $True
You can also check the VPN settings details in the phonebook in:
C:\Users\<User>\AppData\Roaming\Microsoft\Network\Connections\Pbk
Done!

Windows (Server 2012) ifIndex persistence

I'm doing some polling of specific adapters on some PCs running windows via SNMP. I've noticed that polling using an OID constructed with the interface's ifIndex is unreliable as it appears that the ifTable is created dynamically.
I found some Cisco documentation that mentions that ifIndex is no longer persistent as of RFC2863. The documentation introduces a feature of Cisco routers that allows for ifIndex persistence between reboots.
Can such a thing be achieved in Windows? I want to avoid enumeration and identification of interfaces as it is impractical/difficult to do for my application
Unlike (newer, IOS 12+) Cisco devices, Windows does not have a fixed interface scheme.
The interface list is generated on boot and can change while running (think Wireless, dial-up, VPN, or tunneling interfaces; or link loss). That being said, on a stable Windows system the values should be consistent.
I would try the last known value, do a sanity check and re-enumerate the interfaces if it fails.

OSX Link Aggregation for USB tether and WiFi?

Is this kind of link aggregation even possible?
On a Windows machine, there are several 3rd-party applications which make use of bonding and load balancing multiple network interfaces for increased throughput, such as Connectify Dispatcher, for example. Would it be possible to develop such an app for OSX? Is there already any 3rd-party software which does this on OSX? The closest thing I could find was IPNetRouterX, which I've failed to use for bonding USB and WiFi network interfaces.
I have also tried the following line in OSX's terminal:
sudo networksetup -createBond bond0 en1 en3
...where en1 is my WiFi interface and en3 is my USB network interface, which simply results in:
** Error: The parameters were not valid.
Likely, there would need to be some sort of Layer 2 "magic glue" to make this in any way a possibility... but primarily being a Windows programmer, I'm not sure if Apple would enjoy allowing that level of programming access, considering how proprietary they like to be...
Any idea what can be done here?
There are options to networksetup to tell you whether the OS can bond a particular port or not. To do so, you need to hand it a "hardware port", which you can find by using:
networksetup -listallhardwareports
Each of those, in turn, can be queried using
networksetup -isbondsupported <HW Port Name>
Bonded networks are set up using the networksetup port name, not the kernel interface name, so if you were to bond two ethernet networks, you would do so like this:
networksetup -createBond myBondedNet 'Ethernet 1' 'Ethernet 2'
Querying the ports on my 2009 MacPro running 10.9, I find only the hardware ethernet ports to respond YES to the -isbondsupported inquiry.
Note that I didn't have to have the port operational in order for -isbondsupported to return YES, so in my case both of my ethernets responded YES even though only one is currently connected.
gaige thanks for your technical answer but RectangleEquals is not asking how to do Link Aggregation through terminal but
IF Link Aggregation can work for USB, WIFI, or other type of internet connections.
The answer is NO.
Apple didn't created Link Aggregation. It's a separated feature Unix had. Therefore Apple has zero idea how to improve it - nor does it want to spent resource to figure it out because it is not a common enough demand. Even if it wants to give you the feature it will not provide in a regular version of OS X but will provide in a server version and charge you for it.
And there are developers who can do it, by writing a lot of codes - so no free version of such application exist. You can try Connectify Switchboard for OS X.
I found that there is actually no decent way of accomplishing this, thanks to the way that networking is handled via separate interfaces. Although it would be possible to use two separate interfaces to connect to the same remote data source, it would require kernel-level programming skills to get these two interfaces working in unison... And the packets returned through each separate interface would be handled VERY differently, and the network packets would be far too out of sync with each other... So even then, if you were to create some sort of magic bridge to handle all of these situations and somehow use two separate interfaces to pull the same synchronous data, it would end up being (best case scenario) the exact same speed -- but likely SLOWER -- than with just one network interface. Far too much hassle for almost zero benefit.

bluetooth device to windows API via com port

So I have a bluetooth device, this device uses SPP to transfer data between the PC and itself. It connects fine through Windows as a bluetooth device. I can find it, enter the paring code and assign it to a COM port. Now I want to be able to send data through the com port using Windows API but it is refusing to do so.
I suspect that I need to setup the COMMCONFIG Structure correctly (see below)
http://msdn.microsoft.com/en-us/library/aa363188(VS.85).aspx
Unfortunately I have no idea what is the proper setting. I know SPP is supposed to emulate the RS-232 communication... so maybe I have to study up on that to figure out the right setting? Or is there some automatic way to set the COMMCONFIG structure.
I seriously doubt it. If it would be used then you'll have no chance at guessing at the custom provider data without docs from the driver author. Pay attention to the handshake signals, serial port devices routinely ignore anything sent to them when the DTR signal is turned off. And not send anything back with DTR off. A driver would emulate that. Use EscapeCommFunction() to turn them on. Also try a serial comm program like HyperTerminal or Putty to test this so you can isolate the source of the problem.
Why not use the Bluetooth sockets API? No need for troublesome (virtual) COM ports then.
If you're using managed code then see my library 32feet.NET
If using native code, use SOCKADDR_BTH with Winsock connect etc, see e.g. Bluetooth and connect (Windows) Then you can use the standard Winsock send/recv API
Ok, I found that you can use the
GetCommConfig and GetCommState functions to figure out the settings.

Win32 ,Multiple NIC computer , different DNS per NIC , how gethostbyname behaves?

On a win32 multiple nic computer, how to force DNS resolving through gethostbyname() on a specific nic if all nics have different DNS configured and have the same metric ?
Otherwise, how to know which DNS will be used to resolve names each time a gethostbyname() call will be performed by the application ?
You can't do this, at least I'm fairly certain you can't specify an interface to send out the queries from using gethostbyname() or any of the standard socket utilities. (There might be a very esoteric win32 option for this, but I'm betting against it)
If you absolutely need this functionality, you'll need to pick a third party DNS library that provides you with such an ability ... or even write one from scatch.
The library will need to provide you with a means of binding the UDP socket that will be issuing the DNS queries to a specified address.
There also might be a way of configuring Windows to issue DNS queries from an interface using system settings, but I strongly doubt there is a means of doing this from within a program.
That might be better answered at https://serverfault.com/ It's a site geared more toward administering a machine. SO is best for programming.
Consider to use raw sockets and implement your own DNS query mechanism.

Resources