Can WMI query a class property and filter using another class property? - wmi

I am a WMI noob. I'm using BGInfo and have a device with 2 NICs. I'm trying to query the IP address of one of the NICs. I want to submit a query based on the name of the NIC.
However, I'm running into an issue where the IP address is stored in Win32_NetworkAdapterConfiguration and the NIC name is stored in Win32_NetworkAdapter.
I want to build a WMI query like the following:
SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE Win32_NetworkAdapter.Name="My NIC Name".
Is this possible?

For basic understanding, run (from an open cmd window) the following command lines
wmic path Win32_NetworkAdapter get DeviceID, Index, InterfaceIndex, Name, NetConnectionId
wmic path Win32_NetworkAdapterConfiguration get Index, InterfaceIndex, IPAddress
wmic path Win32_NetworkAdapterSetting
and read the following documentation:
Win32_NetworkAdapter class - represents a network adapter of a computer running a Windows operating system (deprecated?),
Win32_NetworkAdapterConfiguration class - represents the attributes and behaviors of a network adapter,
Win32_NetworkAdapterSetting class - association WMI class relates a network adapter and its configuration settings.
Then you can understand how works the following code snippet (if you use a real value for _adapterName instead of the My NIC Name placeholder):
set "_adapterName=My NIC Name"
wmic path Win32_NetworkAdapter where "Name='%_adapterName%'" ASSOC:value /RESULTCLASS:Win32_NetworkAdapterConfiguration
Finally, you can restrict above output to the IPAddress=… line as follows:
wmic path Win32_NetworkAdapter where "Name='%_adapterName%'" ASSOC:value /RESULTCLASS:Win32_NetworkAdapterConfiguration | findstr "^IPAddress"

Related

How to change syslog tag or use my custom tag in rsyslog?

How do I change default syslogtag like "propname[pid]" to my own label in order to distinguish log from different equipment?
I want to collect log from different equipment to a log server. I need to distinguish them by some unique tag like MAC address or serial number other than IP address (may change with network) or hostname (may be same for all equip). How can I add these labels as property or tag into the log?

Get network usage from vmware.vim.vimclient

I'm using the underlying PowerCLI dll's to get some C# functionality and I just can't seem to find the documentation on how to get stat information.
Here's the PowerCLI that I'm trying to recreate in C#.
$vm | Get-Stat -stat 'net.usage.average'
I'm able to log in via VMware.Vim.VimClientImpl#connect method and I'm able to get a VM via the VMware.Vim.VimClient#FindEntityViews method, but from there I have no idea how to pull the network usage information and I haven't been able to find documentation on it via google either.
If there's documentation for these API's I would love to have them, but in the meantime, does anyone know how to pull this information?
I figured out the answer by staring at the SOAP requests and making a few intuitive leaps.
It's my belief that the VMWare API is state based similar to the way the X11 API is state based (you have handles to various objects that sit in memory on the server).
To be specific, you first connect a session to the server and then log in using that session. When you connect to a session vmware returns a list of 'manager objects' and their subsequent MoRef's. So the correct way to query this information is the following:
VimClient vimClient = new VMware.Vim.VimClientImpl();
var serviceContent = vimClient.Connect(hostname, VMware.Vim.CommunicationProtocol.Https, null);
var userSession = vimClient.Login(un, pwd);
NameValueCollection filter = new NameValueCollection();
filter.Add("Name", vmName2LookFor);
String[] viewProperties = null;
var VMs = vimClient.FindEntityViews(typeof(VMware.Vim.VirtualMachine), null, filter, viewProperties);
.Cast<VMware.Vim.VirtualMachine>()
.ToList();
var vm = VMs.FirstOrDefault(); // blindly grab for example purposes
var pm = new VMware.Vim.PerformanceManager(vimClient, serviceContent.PerfManager);
pm.QueryAvailablePerfMetric(vm.MoRef, DateTime.Now.AddDays(-1), DateTime.Now, null)
Note that when creating the PerformanceManager object we hand it the MoRef from the ServiceContent object that was created when originally connecting to the VMWare API.
I believe it's done this way to enable versioning the internal managers, but that specific point is a guess.
Also note that I used vimClient.FindEntityViews for illustrative purposes, there's also a singular vimClient.FindEntityView I could have used.
third note: MoRef stands for "Managed Object Reference".
fourth note: viewProperties in the vimClient.FindEntityViews tells vmware to only send the properties specified, for performance reasons. For example, finding a VM by IP involves grabbing all VM's and doing a search through them all for the VM with the IP you're looking for. You don't care about any other properties, so you tell vmware not to send the other properties. If you have a lot of infrastructure this is a very large speedup in performance. In the above case where I'm interested in the IP address, I would do
String[] viewProperties = new[]{ "Guest.Net" };

How to set DNS server and network interface to boto3?

I would like to upload files to S3 using boto3.
The code will run on a server without DNS configured and I want that the upload process will be routed through a specific network interface.
Any idea if there's any way to solve these issues?
1) add the end point addresses for s3 to /etc/hosts, see this list http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
2) configure a specific route to the network interface, see this info on superuser
https://superuser.com/questions/181882/force-an-application-to-use-a-specific-network-interface
As for setting a network interface, I did a workaround that allows to set the source ip for each connection made by boto.
Just change awsrequest.py AWSHTTPConnection class with the following:
a) Before init() of AWSHTTPConnection add:
source_address = None
b) Inside the init() add:
if AWSHTTPConnection.source_address is not None:
kwargs["source_address"] = AWSHTTPConnection.source_address
Now, from your code you should do the following before you start using boto:
from botocore.awsrequest import AWSHTTPConnection
AWSHTTPConnection.source_address = (source_ip_str, source_port)
Use source_port = 0 in order to let OS choose random port (you probably want this option, see python socket docs for more details)

is there any option to give management or service port as system arguement in wso2 other than portOffset?

I wanted to pass the management console port(specified in catalina-server) and service http port(specified in axis2.xml) as system properties (using -DmgmntPort=9292 -DservPort=8282) while starting wso2 server. I tried -DhttpsPort but not working. please help
I don't think there is an option to allow such usage. I looked into startup script and found, that port always by default 9443, but you can configure offset.
It means if u have offset 10 then actual port number will be 9453 = 9443 + 10
example of such command bellow. Lets consider that u distribution located in /var/lib/wso2esb-4.9.0
rename WSO_HOME/repository/conf/carbon.xml to carbon.original.xml
then add to startup script handler for input variale of offset. Lets call it offset
command
sed "s/<Offset>0<\/Offset>/<Offset>$offset<\/Offset>/" /var/lib/wso2esb-4.9.0/repository/conf/carbon.original.xml > /var/lib/wso2esb-4.9.0./repository/conf/carbon.xml
will create new carbon.xml in proper directory and it will be used to configure ports.
Use -DportOffset= [offset value] when you start the server.
Ex:
./wso2server.sh -DportOffset=3

Generate a tree from a text file using python

I Have a txt file which has data like this:
arp
show
show ip
show ip route
show ip route static
show ip default-gateway
show ip default-gateway static
show ip interface
show partition
no
no logging
no logging on
no logging override
I have to print a tree in the following way:
arp
show
ip
route
static
default-gateway
static
interface
partition
no
logging
on
override
Thanks in advance for the help!!!
The count of words - 1 indicates tab depth. Loop through each line and prepend a tab using this heuristic in combination with pulling only word X for display.