Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

MAC adress

imeca
Beginner
1,412 Views

Hello friends,

Iwill be grateful if anyone help me to find the mac adress(es) of the PC using only fortran code.

thank you in advance.

0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
1,412 Views
Quoting - imeca

Hello friends,

Iwill be grateful if anyone help me to find the mac adress(es) of the PC using only fortran code.

thank you in advance.

Test...

New forum bug: when you compose the post and the sending fails, when you hit "back" in the browser, your work is lost.

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,412 Views
Quoting - Jugoslav Dujic

Test...

New forum bug: when you compose the post and the sending fails, when you hit "back" in the browser, your work is lost.

So, composing it again:

We had this thread back in 2004:

http://software.intel.com/en-us/forums/showthread.php?t=40833

It lead to this MSDN Visual Basic example:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q175472

Note that Intel Fortran now has all the API stuff declared (I verified at least for T_ADAPTER_STATUS), so you won't have to go through the hoops as the original poster back then. Just declare and use the TYPEs and functions.

0 Kudos
yamajun2
Beginner
1,412 Views
Quoting - imeca

Hello friends,

Iwill be grateful if anyone help me to find the mac adress(es) of the PC using only fortran code.

thank you in advance.

Hi,

Here is my program to get MAC ADDRESS by Fortran.
http://d.hatena.ne.jp/fortran66/20080228

It is wriiten in Japanese, but Isuppose you can guess!

You have to add "iphlpapi.lib" to Linker->Input->Additional Dependencies.

Yamajun

[cpp]PROGRAM MAC
USE ifwinty
IMPLICIT NONE
!
INTEGER, PARAMETER :: MAX_ADAPTER_DESCRIPTION_LENGTH = 128 !// arb.
INTEGER, PARAMETER :: MAX_ADAPTER_NAME_LENGTH        = 256 !// arb.
INTEGER, PARAMETER :: MAX_ADAPTER_ADDRESS_LENGTH     =   8 !// arb.
!
TYPE :: IP_ADDRESS_STRING
  CHARACTER (4) :: String(4)
END TYPE
TYPE :: IP_MASK_STRING
  CHARACTER (4) :: String(4)
END TYPE
!
TYPE :: t_IP_ADDR_STRING 
 INTEGER (LPLONG) :: pNext
 TYPE (IP_ADDRESS_STRING) :: IpAddress
 TYPE (IP_MASK_STRING) :: IpMask
 INTEGER (DWORD)      :: Context
END TYPE
!
TYPE :: t_IP_ADAPTER_INFO
 INTEGER (LPLONG) :: pNext 
 INTEGER (DWORD) :: ComboIndex
 CHARACTER (LEN = MAX_ADAPTER_NAME_LENGTH + 4) :: AdapterName
 CHARACTER (LEN = MAX_ADAPTER_DESCRIPTION_LENGTH + 4) :: Description
 INTEGER (UINT) :: AddressLength
 INTEGER (BYTE) :: Address(MAX_ADAPTER_ADDRESS_LENGTH)
 INTEGER (DWORD) :: Index
 INTEGER (ULONG) :: iType
 INTEGER (ULONG) :: DhcpEnabled
 INTEGER (LPLONG) :: pCurrentIpAddress 
 TYPE (t_IP_ADDR_STRING) :: IpAddressList
 TYPE (t_IP_ADDR_STRING) :: GatewayList
 TYPE (t_IP_ADDR_STRING) :: DhcpServer
 INTEGER (BOOL) :: HaveWins
 TYPE (t_IP_ADDR_STRING) :: PrimaryWinsServer
 TYPE (t_IP_ADDR_STRING) :: SecondaryWinsServer
 INTEGER (ULONG) :: LeaseObtained
 INTEGER (ULONG) :: LeaseExpires;
END TYPE 
!
INTERFACE
 INTEGER (BOOL) FUNCTION GetAdaptersInfo(arg1, arg2)
 USE ifwinty
 !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'GetAdaptersInfo' :: GetAdaptersInfo
 INTEGER (LPLONG) :: arg1
 INTEGER (LPLONG) :: arg2
 END FUNCTION
END INTERFACE
!
TYPE (t_IP_ADAPTER_INFO) :: AdapterInfo(16)
TYPE (t_IP_ADDR_STRING) :: CurrentIpAddress
INTEGER (DWORD) :: dwRetVal 
INTEGER (BOOL) :: iret
INTEGER :: i
dwRetVal = sizeof(AdapterInfo)
iret = GetAdaptersInfo(LOC(AdapterInfo), LOC(dwRetVal))
IF (iret /= 0) STOP 'Error'
DO i = 1, 16
! PRINT *, AdapterInfo(1)%pNext
! PRINT *, AdapterInfo(1)%ComboIndex
! PRINT *, AdapterInfo(1)%AddressLength
 PRINT *, AdapterInfo(1)%Description(1:INDEX(AdapterInfo(1)%Description(1:128), CHAR(0)))
 PRINT '(5(Z2.2,"-"), Z2.2)', AdapterInfo(i)%Address(1:AdapterInfo(i)%AddressLength)
 PRINT *, AdapterInfo(1)%IpAddressList
 IF (AdapterInfo(i)%pNext == NULL) EXIT
END DO
STOP
END PROGRAM MAC[/cpp]
0 Kudos
Paul_Curtis
Valued Contributor I
1,412 Views

Works very well, thank you.

0 Kudos
Reply