How to Fetch The Logical Name of a Nic Card Given The Ip Address Associated with It

How to fetch the logical name of a NIC card given the ip address associated with it ?

Take this:

#!/bin/sh
ip=192.168.1.10
iface=$(ip addr | grep $ip | awk '{print $NF}')
echo "Iface is: ${iface}"

Retrieve the name of a Network Interface using an IP Address and AWK Bash

I don't have CentOS, but in RHEL, IP address is listed as inet address. I believe they should be same.

The following command should give you the interface name which has a IP address.

export iface=$(ifconfig | grep -B1 "inet addr:x.x.x.x" | awk '$1!="inet" && $1!="--" {print $1}')

echo "$iface" # To get the interface name for x.x.x.x ip

And this one should show the IP including localhost :

ifconfig | grep "inet addr:" | sed -e 's/addr:/addr: /g' | awk '{print $3}'

C Programming: Check if the IP address is added on any given NIC

The method(GETIFADDRS) suggested above is correct solution for the stated problem description. The getifaddrs browses through all the IP's on the NIC.

However in my case there are many IP's addresses added on the NIC/system and I am OK with knowing if the IP is present in any of the NIC. I found a easier/faster solution.

To check if the IP is added on any of the NIC card of the machine, just open a TCP socket and bind with port=zero(0) and the IP address to be checked. The successful bind will suggest that the IP is available/present.

Note: This works if IP is added on any of the NIC card in the system. The port zero should be used instead of hard-coding as it selects any available port on in the system
(ref. http://compnetworking.about.com/od/tcpip/p/port-numbers-0.htm)

This method is tested for both IPv4/IPv6 in UNIX environment(rhel)

PS:Do not forget to close the socket after verifying the presence of IP

How to get Network Interface Card names in Python?

I don't think there's anything in the standard library to query these names.

If I needed these names on a Linux system I would parse the output of ifconfig or the contents of /proc/net/dev. Look at this blog entry for a similar problem.

Get list of 'Friendly interface names' on a Mac (Airport, Ethernet, etc)

networksetup -listallnetworkservices will give you just the names (with an asterisk before disabled ports, in case you want to leave them out). networksetup -listnetworkserviceorder gives some additional info, like what /dev entry (en0, etc) they correspond to. Check the man page for networksetup for even lots more options...

Add Member to get NIC Info Gives Error for Servers with More than One Nic ( powershell.)

Try this:

Get-WmiObject Win32_NetworkAdapter -ComputerName $computer| ForEach-Object {    
$NetConnectionId = $_.NetConnectionId
$nac = $_.GetRelated('Win32_NetworkAdapterconfiguration') | Select-Object IPEnabled,DHCPEnabled,IPAddress,IPSubnet,DefaultIPGateway,DHCPServer,DNSDomain,DNSDomainSuffixSearchOrder,DNSServerSearchOrder
$nac | Select-Object *,@{Name='NetConnectionId';Expression={$NetConnectionId}}
}

UPDATE (per poster request):

$compname='.'
$colItems1 = get-wmiobject -class Win32_NetworkAdapter -computername $compname
$colItems = get-wmiobject -class Win32_NetworkAdapterconfiguration -computername $compname

foreach ($objitem in $colItems)
{
$objItem1 = $colItems1 | where-object{$_.Caption -eq $objItem.Caption}

if ($objItem.ipenabled -eq $true -and $objitem1.netconnectionid)
{
$output = new-object -typename psobject
$output | Add-Member -MemberType Noteproperty -Name NICCardName -Value $objitem1.netconnectionid
$output | Add-Member -MemberType Noteproperty -Name DHCPEnabled -Value $objItem.DHCPEnabled
$output | Add-Member -MemberType Noteproperty -Name IPAddress -Value $objItem.IPAddress
$output | Add-Member -MemberType Noteproperty -Name SubnetMask -Value $objItem.IPSubnet
$output | Add-Member -MemberType Noteproperty -Name Gateway -Value $objItem.DefaultIPGateway
$output | Add-Member -MemberType Noteproperty -Name DHCPServer -Value $objItem.DHCPServer
$output | Add-Member -MemberType Noteproperty -Name DNSDomain -Value $objItem.DNSDomain
$output | Add-Member -MemberType Noteproperty -Name DNSDomainSuffixSearchOrder -Value $objItem.DNSDomainSuffixSearchOrder
$output | Add-Member -MemberType Noteproperty -Name DNSServerSearchOrder -Value $objItem.DNSServerSearchOrder -PassThru

}
}

On solaris, is there a command to get the Ethernet Card MAC Address without being root

Try an "arp -a", and look for your own hostname. (This works for me on the Solaris 9 machine I tried it on, but your mileage may vary.)

How to cut ifconfig to get eth* details alone?

With grep & ifconfig :

ifconfig | grep -o '^eth[0-9]\+'

Or with only grep :

grep -oP '^ *\Keth[0-9]+' /proc/net/dev

What does the meaning of [fixed] string in output of ethtool command

Those are the parameters that cant be changed, they are "fixed".

Here is an example. Let's take this output of ethtool :

large-receive-offload: off [fixed]
rx-vlan-offload: on
tx-vlan-offload: on

If I want to change rx-vlan-offload I would do :

$ sudo ethtool -K eth0 rxvlan off
Actual changes:
tcp-segmentation-offload: on
tx-tcp-segmentation: on
tx-tcp6-segmentation: on
rx-vlan-offload: off

The result will be :

$ sudo ethtool -k eth0 | grep rx-vlan
rx-vlan-offload: **off**
rx-vlan-filter: off [fixed]
rx-vlan-stag-hw-parse: off [fixed]
rx-vlan-stag-filter: off [fixed]

Now, let's try to modify a "fixed" parameter like "large-receive-offload" :

$ sudo ethtool -K eth0 lro on
Cannot change large-receive-offload
Could not change any device features

Hope this helps.



Related Topics



Leave a reply



Submit