- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- convert netmask ffffff00 to decimal
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 11:22 AM
тАО11-22-2004 11:22 AM
I need to get the netmask of each lan cards in my systems, so i use the following:
var=`ifconfig $lan |grep inet|awk '{print $4}'`
var equals ffffff00 which in decimal is 255.255.255.0
My problem is to make my script return the decimal value using something like:
echo "16i ${VAR} p" | dc
But I cannot use the hole 8bit through dc, I need to cut the 8 bits into 4 portions of 2 bits and pass one portion at a time.
Does anyone know a way to cut the 8bit hex mask ? or maybe there is a better way to get the netmask value in decimal of each lan cards.
any help would be appreciated,
thanks
Sebastien
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 12:10 PM
тАО11-22-2004 12:10 PM
Re: convert netmask ffffff00 to decimal
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter in colAdapters
Wscript.Echo "Host name: " & objAdapter.DNSHostName
Wscript.Echo "DNS domain: " & objAdapter.DNSDomain
Wscript.Echo "DNS suffix search list: " & objAdapter.DNSDomainSuffixSearchOrder
Wscript.Echo "Description: " & objAdapter.Description
Wscript.Echo "Physical address: " & objAdapter.MACAddress
Wscript.Echo "DHCP enabled: " & objAdapter.DHCPEnabled
If Not IsNull(objAdapter.IPAddress) Then
For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
Wscript.Echo "IP address: " & objAdapter.IPAddress(i)
Next
End If
If Not IsNull(objAdapter.IPSubnet) Then
For i = LBound(objAdapter.IPSubnet) To UBound(objAdapter.IPSubnet)
Wscript.Echo "Subnet: " & objAdapter.IPSubnet(i)
Next
End If
If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = LBound(objAdapter.DefaultIPGateway) To UBound(objAdapter.DefaultIPGateway)
Wscript.Echo "Default gateway: " & objAdapter.DefaultIPGateway(i)
Next
End If
Wscript.Echo "DHCP server: " & objAdapter.DHCPServer
If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = LBound(objAdapter.DNSServerSearchOrder) To UBound(objAdapter.DNSServerSearchOrder)
Wscript.Echo "DNS server: " & objAdapter.DNSServerSearchOrder(i)
Next
End If
Wscript.Echo "Primary WINS server: " & objAdapter.WINSPrimaryServer
Wscript.Echo "Secondary WINS server: " & objAdapter.WINSSecondaryServer
Wscript.Echo "Lease obtained: " & objAdapter.DHCPLeaseObtained
Wscript.Echo "Lease expires: " & objAdapter.DHCPLeaseExpires
Next
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 05:32 PM
тАО11-22-2004 05:32 PM
Solutionvar=`ifconfig $lan |grep inet|awk '{print $4}'`
oct1=0x`echo $var | cut -c 1-2`
oct2=0x`echo $var | cut -c 3-4`
oct3=0x`echo $var | cut -c 5-6`
oct4=0x`echo $var | cut -c 7-8`
printf "Subnet: %d.%d.%d.%d" $oct1 $oct2 $oct3 $oct4
Now the trick is
printf "%d" 0xHEXNUMBER returns the decimal of the hexadecimal number.
printf "%x" DECIMALNUMBER returns the hexadecimalnumber of the decimal number
HTH
Regards
Gerhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 05:34 PM
тАО11-22-2004 05:34 PM
Re: convert netmask ffffff00 to decimal
"But I cannot use the hole 8byte through dc, I need to cut the 8 bytes into 4 portions of 2 bytes and pass one portion at a time.
Does anyone know a way to cut the 8byte hex mask ? or maybe there is a better way to get the netmask value in decimal of each lan cards."
Regards
Gerhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-23-2004 12:11 AM
тАО11-23-2004 12:11 AM
Re: convert netmask ffffff00 to decimal
Gerhard, "cut" is exactly what I was looking for, thanks man, and you are right about the bits and bytes ;)
take care guys,
Sebastien
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-23-2004 12:13 AM
тАО11-23-2004 12:13 AM