Olá a todos,
Já temos na nossa casa exemplos, no entanto partilho código para ober:
IP Local
IP Publico
MAC Address
Exemplo construído através de código partilhado por Christos Samaras no link abaixo:
myengineeringworld.net/2014/12/get-public-ip-local-ip-mac-address-vba.html
Funções:
Quem quiser usar para Proteção dos seus sistemas, pode completar com mais segurança através do exemplo postado pelo JPaulo:
https://www.maximoaccess.com/t32447-numero-de-serie-da-motherboard-do-hd
Abraço e bons estudos!
Já temos na nossa casa exemplos, no entanto partilho código para ober:
IP Local
IP Publico
MAC Address
Exemplo construído através de código partilhado por Christos Samaras no link abaixo:
myengineeringworld.net/2014/12/get-public-ip-local-ip-mac-address-vba.html
Funções:
- Código:
Function GetMyLocalIP() As String
'----------------------------------------------------------------------------------------------
'Origem: https://www.myengineeringworld.net/2014/12/get-public-ip-local-ip-mac-address-vba.html
'----------------------------------------------------------------------------------------------
'Written By: Christos Samaras
'Date: 22/11/2014
'E-mail: xristos.samaras@gmail.com
'Site: http://www.myengineeringworld.net
'----------------------------------------------------------------------------------------------
'Declaring the necessary variables.
Dim strComputer As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim myIPAddress As String
'Set the computer.
strComputer = "."
'The root\cimv2 namespace is used to access the Win32_NetworkAdapterConfiguration class.
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'A select query is used to get a collection of IP addresses from the network adapters that have the property IPEnabled equal to true.
Set colItems = objWMIService.ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
'Loop through all the objects of the collection and return the first non-empty IP.
For Each objItem In colItems
If Not IsNull(objItem.IPAddress) Then myIPAddress = Trim(objItem.IPAddress(0))
Exit For
Next
'Return the IP string.
GetMyLocalIP = myIPAddress
End Function
- Código:
Function GetMyPublicIP() As String
'----------------------------------------------------------------------------------------------
'Origem: https://www.myengineeringworld.net/2014/12/get-public-ip-local-ip-mac-address-vba.html
'----------------------------------------------------------------------------------------------
'Written By: Christos Samaras
'Date: 22/11/2014
'E-mail: xristos.samaras@gmail.com
'Site: http://www.myengineeringworld.net
'----------------------------------------------------------------------------------------------
Dim HttpRequest As Object
On Error Resume Next
'Create the XMLHttpRequest object.
Set HttpRequest = CreateObject("MSXML2.XMLHTTP")
'Check if the object was created.
If Err.Number <> 0 Then
'Return error message.
GetMyPublicIP = "Could not create the XMLHttpRequest object!"
'Release the object and exit.
Set HttpRequest = Nothing
Exit Function
End If
On Error GoTo 0
'Create the request - no special parameters required.
HttpRequest.Open "GET", "http://myip.dnsomatic.com", False
'Send the request to the site.
HttpRequest.Send
'Return the result of the request (the IP string).
GetMyPublicIP = HttpRequest.ResponseText
End Function
- Código:
Function GetMyMACAddress() As String
'----------------------------------------------------------------------------------------------
'Origem: https://www.myengineeringworld.net/2014/12/get-public-ip-local-ip-mac-address-vba.html
'----------------------------------------------------------------------------------------------
'Written By: Christos Samaras
'Date: 22/11/2014
'E-mail: xristos.samaras@gmail.com
'Site: http://www.myengineeringworld.net
'----------------------------------------------------------------------------------------------
'Declaring the necessary variables.
Dim strComputer As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim myMACAddress As String
'Set the computer.
strComputer = "."
'The root\cimv2 namespace is used to access the Win32_NetworkAdapterConfiguration class.
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'A select query is used to get a collection of network adapters that have the property IPEnabled equal to true.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
'Loop through all the collection of adapters and return the MAC address of the first adapter that has a non-empty IP.
For Each objItem In colItems
If Not IsNull(objItem.IPAddress) Then myMACAddress = objItem.MACAddress
Exit For
Next
'Return the IP string.
GetMyMACAddress = myMACAddress
End Function
Quem quiser usar para Proteção dos seus sistemas, pode completar com mais segurança através do exemplo postado pelo JPaulo:
https://www.maximoaccess.com/t32447-numero-de-serie-da-motherboard-do-hd
Abraço e bons estudos!
- Anexos
- IP_Local_Publico_MAC_Pro_MB.zip
- Atualização com ID Processador e Numero Serie da Motherboard
- Você não tem permissão para fazer download dos arquivos anexados.
- (31 Kb) Baixado 177 vez(es)
Última edição por ahteixeira em 19/12/2018, 16:00, editado 2 vez(es)