- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am licencing computerprograms to other people. Is there any Fortran routine that can be used to
identify a specific computer, etiher the physical adress or the CPU unit?
Best regards
Reidar
identify a specific computer, etiher the physical adress or the CPU unit?
Best regards
Reidar
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not reliably. This topic comes up from time to time, and my usual recommendation is to look for a licensing library, but many of these are expensive. You can get the MAC address of an Ethernet adapter without too much difficulty. That is generally unique, but can be spoofed. Nothing else is reasonably reliable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use the command getmac to get the MAC address of the computer and identify it that way.
It can be issued from a DOS prompt command window, so you could use the SYSTEM command to execute it.
I'm not sure how you manage the reply text though!
As Steve said, there are license programs you can use which use keys matched to the computer, if you need to do so. Quicklicense Manager from Interactive studios worked OK for me when I tried it.
It can be issued from a DOS prompt command window, so you could use the SYSTEM command to execute it.
I'm not sure how you manage the reply text though!
As Steve said, there are license programs you can use which use keys matched to the computer, if you need to do so. Quicklicense Manager from Interactive studios worked OK for me when I tried it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a Fortran invocation of WinAPI code to obtain the computer's MAC and IP addresses for multiple network adapters which may be present:
[bash]MODULE MAC USE ifwinty IMPLICIT NONE PUBLIC GetMacInfo PRIVATE SAVE INTEGER, PARAMETER :: MAX_ADAPTER_DESCRIPTION_LENGTH = 128 INTEGER, PARAMETER :: MAX_ADAPTER_NAME_LENGTH = 256 INTEGER, PARAMETER :: MAX_ADAPTER_ADDRESS_LENGTH = 8 INTEGER, PARAMETER :: MIB_IF_TYPE_ETHERNET = 6 ! Ipifcons.h TYPE IP_ADDRESS_STRING CHARACTER(LEN=16) :: String END TYPE IP_ADDRESS_STRING TYPE IP_MASK_STRING CHARACTER(LEN=16) :: String END TYPE IP_MASK_STRING TYPE t_IP_ADDR_STRING INTEGER (LPLONG) :: pNext TYPE (IP_ADDRESS_STRING) :: IpAddress TYPE (IP_MASK_STRING) :: IpMask INTEGER (DWORD) :: Context END TYPE t_IP_ADDR_STRING 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 t_IP_ADAPTER_INFO ! must link with IpHlpApi.lib to access this API function; ! this interface is not included in ifwinty 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 CONTAINS SUBROUTINE GetMacInfo (hwnd, id) USE contwrap IMPLICIT NONE ! dialog window handle and set of static-text IDs for display INTEGER(HANDLE), INTENT(IN) :: hwnd INTEGER, INTENT(IN), DIMENSION(4) :: id CHARACTER(LEN=200) :: msg INTEGER :: i, nc, count INTEGER, PARAMETER :: acount = 16 TYPE(t_IP_ADAPTER_INFO),ALLOCATABLE :: ai(:) count = 0 ! allow for multiple adapters ALLOCATE (ai(acount)) nc = SIZEOF(ai) IF (GetAdaptersInfo(LOC(ai), LOC(nc)) == 0) THEN DO i = 1, acount SELECT CASE (ai(i)%iType) CASE (MIB_IF_TYPE_ETHERNET) ! line 1: description and MAC address !nc = INDEX(ai(i)%Description, CHAR(0)) - 1 !WRITE (msg, '(A,", ",5(Z2.2,"-"),Z2.2)') & ! ai(i)%Description(1:nc), & ! ai(i)%Address(1:ai(i)%AddressLength) nc = INDEX(ai(i)%Description, CHAR(0)) msg = ai(i)%Description(1:nc) count = count + 1 CALL StaticSetText (hwnd, id(count), msg) CALL ControlSetVisible (hwnd, id(count), .TRUE.) ! line 2: IP and Gateway addresses WRITE (msg, '("IP Addr: ",A," Gateway: ",A)') & ai(i)%IpAddressList%IpAddress%string, & ai(i)%GatewayList%IpAddress%string CALL remove_nulls (msg) count = count + 1 CALL StaticSetText (hwnd, id(count), msg) CALL ControlSetVisible (hwnd, id(count), .TRUE.) IF (count >= 4) EXIT END SELECT IF (ai(i)%pNext == NULL) EXIT END DO END IF DEALLOCATE (ai) END SUBROUTINE GetMacInfo END MODULE MAC [/bash]
[bash]MODULE MAC USE ifwinty IMPLICIT NONE PUBLIC GetMacInfo PRIVATE SAVE INTEGER, PARAMETER :: MAX_ADAPTER_DESCRIPTION_LENGTH = 128 INTEGER, PARAMETER :: MAX_ADAPTER_NAME_LENGTH = 256 INTEGER, PARAMETER :: MAX_ADAPTER_ADDRESS_LENGTH = 8 INTEGER, PARAMETER :: MIB_IF_TYPE_ETHERNET = 6 ! Ipifcons.h TYPE IP_ADDRESS_STRING CHARACTER(LEN=16) :: String END TYPE IP_ADDRESS_STRING TYPE IP_MASK_STRING CHARACTER(LEN=16) :: String END TYPE IP_MASK_STRING TYPE t_IP_ADDR_STRING INTEGER (LPLONG) :: pNext TYPE (IP_ADDRESS_STRING) :: IpAddress TYPE (IP_MASK_STRING) :: IpMask INTEGER (DWORD) :: Context END TYPE t_IP_ADDR_STRING 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 t_IP_ADAPTER_INFO ! must link with IpHlpApi.lib to access this API function; ! this interface is not included in ifwinty 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 CONTAINS SUBROUTINE GetMacInfo (hwnd, id) USE contwrap IMPLICIT NONE ! dialog window handle and set of static-text IDs for display INTEGER(HANDLE), INTENT(IN) :: hwnd INTEGER, INTENT(IN), DIMENSION(4) :: id CHARACTER(LEN=200) :: msg INTEGER :: i, nc, count INTEGER, PARAMETER :: acount = 16 TYPE(t_IP_ADAPTER_INFO),ALLOCATABLE :: ai(:) count = 0 ! allow for multiple adapters ALLOCATE (ai(acount)) nc = SIZEOF(ai) IF (GetAdaptersInfo(LOC(ai), LOC(nc)) == 0) THEN DO i = 1, acount SELECT CASE (ai(i)%iType) CASE (MIB_IF_TYPE_ETHERNET) ! line 1: description and MAC address !nc = INDEX(ai(i)%Description, CHAR(0)) - 1 !WRITE (msg, '(A,", ",5(Z2.2,"-"),Z2.2)') & ! ai(i)%Description(1:nc), & ! ai(i)%Address(1:ai(i)%AddressLength) nc = INDEX(ai(i)%Description, CHAR(0)) msg = ai(i)%Description(1:nc) count = count + 1 CALL StaticSetText (hwnd, id(count), msg) CALL ControlSetVisible (hwnd, id(count), .TRUE.) ! line 2: IP and Gateway addresses WRITE (msg, '("IP Addr: ",A," Gateway: ",A)') & ai(i)%IpAddressList%IpAddress%string, & ai(i)%GatewayList%IpAddress%string CALL remove_nulls (msg) count = count + 1 CALL StaticSetText (hwnd, id(count), msg) CALL ControlSetVisible (hwnd, id(count), .TRUE.) IF (count >= 4) EXIT END SELECT IF (ai(i)%pNext == NULL) EXIT END DO END IF DEALLOCATE (ai) END SUBROUTINE GetMacInfo END MODULE MAC [/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You cannot assume that the CPU on any PC will have a software-accessible serial number. For Windows, many software vendors use the disk serial number to identify the system, instead of the MAC. Here is a short program that makes a Kernel32 call to ascertain the DSNo.
[fortran]program getvsn use kernel32 implicit none character(len=4) :: diskpth = 'C:'C character(len=20) :: volname,fsname integer(LPDWORD) :: VolSno,Zero=0 integer(BOOL) :: rc rc = GetVolumeInformation( & diskpth, & volname, & 20, & %LOC(VolSno), & NULL, & NULL, & fsname, & 20); write(*,'(1x,I2,2x,Z4,"-",Z4,2x,A10,2x,A10)') & rc,rshift(VolSno,16),iand(VolSno,Z'0000FFFF'), & volname,fsname end program getvsn [/fortran]
[fortran]program getvsn use kernel32 implicit none character(len=4) :: diskpth = 'C:'C character(len=20) :: volname,fsname integer(LPDWORD) :: VolSno,Zero=0 integer(BOOL) :: rc rc = GetVolumeInformation( & diskpth, & volname, & 20, & %LOC(VolSno), & NULL, & NULL, & fsname, & 20); write(*,'(1x,I2,2x,Z4,"-",Z4,2x,A10,2x,A10)') & rc,rshift(VolSno,16),iand(VolSno,Z'0000FFFF'), & volname,fsname end program getvsn [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regarding posts fromPaul, Steve and Mecej4:
Guys,
I'm a 100%C/C++ Software Developer and by reading your posts on the Fortran forum I'm thinking
about starting some Fortran programming ( forR&D).
Your postsare awesome!
Thank you and Best regards,
Sergey
Guys,
I'm a 100%C/C++ Software Developer and by reading your posts on the Fortran forum I'm thinking
about starting some Fortran programming ( forR&D).
Your postsare awesome!
Thank you and Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've no doubt that Steve's continued efforts over the years, including running these forum sites, have contributed strongly to the continued viability of Fortran.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page