Get Mac adress in datbabase
emaduldeen, June 18, 2022 - 7:38 pm UTC
i make a class and in working fine in eclipse
--------
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
public class MACAddress {
public static void main(String[] args) throws Exception
{
// instantiate the MACAddress class
MACAddress obj = new MACAddress();
// call the getMAC() method on the current object
// passing the localhost address as the parameter
//obj.getMAC();
System.out.println( "getMacWindow2="+getMacWindow2() );
System.out.println( "getMacWindow="+getMacWindow() );
System.out.println( "getMac="+getMAC() );
}
// method to get the MAC addresses of the
// localhost machine
public static String getMAC ()
{
String stMac = "adress is :";
try {
// create an Enumeration of type
// NetworkInterface and store the values
// returned by
// NetworkInterface.getNetworkInterfaces()
// method
Enumeration<NetworkInterface> networks
= NetworkInterface.getNetworkInterfaces();
// for every network in the networks Enumeration
while (networks.hasMoreElements()) {
NetworkInterface network
= networks.nextElement();
// call getHardwareAddress() method on each
// network and store the returned value in a
// byte array
byte[] mac = network.getHardwareAddress();
if (mac != null) {
// convert the obtained byte array into
// a printable String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format(
"%02X%s", mac[i],
(i < mac.length - 1) ? "-"
: ""));
}
// print the final String containing the
// MAC Address
//System.out.print(sb.toString()+",");
stMac = stMac+ sb.toString()+"," ;
}
}
}
catch (SocketException e) {
e.printStackTrace();
}
return stMac;
}
public static String getMacWindow() throws SocketException, UnknownHostException
{
// create a variable of type NetworkInterface and
// assign it with the value returned by the
// getByInetAddress() method
String machinMacAdress = "";
InetAddress addr = InetAddress.getLocalHost();
// instantiate the MACAddress class
//MACAddress obj = new MACAddress();
//System.out.print("MAC Address of the system : ");
// call the getMAC() method on the current object
// passing the localhost address as the parameter
NetworkInterface iface
= NetworkInterface.getByInetAddress(addr);
// create a byte array and store the value returned
// by the NetworkInterface.getHardwareAddress()
// method
byte[] mac = iface.getHardwareAddress();
// convert the obtained byte array into a printable
// String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format(
"%02X%s", mac[i],
(i < mac.length - 1) ? "-" : ""));
}
// print the final String containing the MAC Address
//System.out.println(sb.toString());
machinMacAdress = sb.toString() ;
return machinMacAdress;
}
public static String getMacWindow2() {
InetAddress ip;
String myMacAdress = null ;
try {
ip = InetAddress.getLocalHost();
System.out.println("IP address : " + ip.getHostAddress());
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
System.out.print("MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
System.out.println(sb.toString());
myMacAdress=sb.toString() ;
} catch (Exception e) {
e.printStackTrace();
}
return myMacAdress;
}
}
---------
import it in database
and make package
--------
CREATE OR REPLACE PACKAGE SYS.MACADDRESS AS
PROCEDURE main(Param1 VARCHAR2)
AS
LANGUAGE java
NAME 'MACAddress.main(java.lang.String[])';
FUNCTION getMAC
return VARCHAR2
AS
LANGUAGE java
NAME 'MACAddress.getMAC() return java.lang.String';
FUNCTION getMacWindow
return VARCHAR2
AS
LANGUAGE java
NAME 'MACAddress.getMacWindow() return java.lang.String';
FUNCTION getMacWindow2
return VARCHAR2
AS
LANGUAGE java
NAME 'MACAddress.getMacWindow2() return java.lang.String';
FUNCTION getClass
return VARCHAR2
AS
LANGUAGE java
NAME 'MACAddress.getClass() return java.lang.Class';
FUNCTION hashCode
return NUMBER
AS
LANGUAGE java
NAME 'MACAddress.hashCode() return int';
FUNCTION equals(Param1 VARCHAR2)
return VARCHAR2
AS
LANGUAGE java
NAME 'MACAddress.equals(java.lang.Object) return boolean';
FUNCTION toString
return VARCHAR2
AS
LANGUAGE java
NAME 'MACAddress.toString() return java.lang.String';
PROCEDURE notify
AS
LANGUAGE java
NAME 'MACAddress.notify()';
PROCEDURE notifyAll
AS
LANGUAGE java
NAME 'MACAddress.notifyAll()';
PROCEDURE wait(Param1 NUMBER)
AS
LANGUAGE java
NAME 'MACAddress.wait(long)';
PROCEDURE wait(Param1 NUMBER, Param2 NUMBER)
AS
LANGUAGE java
NAME 'MACAddress.wait(long, int)';
PROCEDURE wait
AS
LANGUAGE java
NAME 'MACAddress.wait()';
end;
/
and when i use database
select MACADDRESS.getMacwindow2
from dual
return null
July 05, 2022 - 12:19 am UTC
Skip the java ... just use an an external table. Example from Windows
getmac.cmd
===========
@echo off
set SystemRoot=C:\WINDOWS
ipconfig /all | grep Physical | gawk -F: "{print $2}"
SQL> create table addr
2 (
3 mac varchar2(100)
4 )
5 organization external
6 ( type oracle_loader
7 default directory temp
8 access parameters
9 ( records delimited by newline
10 preprocessor temp:'getmac.cmd'
11 )
12 location ( temp:'getmac.cmd' )
13 ) reject limit unlimited ;
Table created.
SQL> select * from addr;
MAC
------------------------------------------------
12-AF-97-7E-89-5E
65-00-27-00-A7-1A
A2-B6-C0-7D-93-96
11-FF-48-C8-0E-11
9C-B6-C2-FE-0C-0E
Get Mac adress in datbabase
emaduldeen, June 18, 2022 - 7:39 pm UTC
i am using oracle 12 c , i think it is using java 8
All Required Steps To Get MAC Address
Mohamed Younis, September 28, 2022 - 8:42 am UTC
Would you please give us all steps with it is explanations because when I try to do it i couldn't
September 29, 2022 - 12:31 am UTC
which platform?
A reader, October 10, 2022 - 1:53 pm UTC
Iam using Oracle Apex
October 11, 2022 - 3:27 am UTC
So you saw my external table example.
Then on a page in APEX, you could just create an item and you're done!
select mac
into :P1_MY_ITEM
from addr;
Get Logged User MAC Address Using Oracle Apex
Mohamed Younis, October 12, 2022 - 6:38 am UTC
Thanks for your reply,
I don't know how to create this java class or how to import it into Oracle Database
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
public class MACAddress {
public static void main(String[] args) throws Exception
{
// instantiate the MACAddress class
MACAddress obj = new MACAddress();
// call the getMAC() method on the current object
// passing the localhost address as the parameter
//obj.getMAC();
System.out.println( "getMacWindow2="+getMacWindow2() );
System.out.println( "getMacWindow="+getMacWindow() );
System.out.println( "getMac="+getMAC() );
}
// method to get the MAC addresses of the
// localhost machine
public static String getMAC ()
{
String stMac = "adress is :";
try {
// create an Enumeration of type
// NetworkInterface and store the values
// returned by
// NetworkInterface.getNetworkInterfaces()
// method
Enumeration<NetworkInterface> networks
= NetworkInterface.getNetworkInterfaces();
// for every network in the networks Enumeration
while (networks.hasMoreElements()) {
NetworkInterface network
= networks.nextElement();
// call getHardwareAddress() method on each
// network and store the returned value in a
// byte array
byte[] mac = network.getHardwareAddress();
if (mac != null) {
// convert the obtained byte array into
// a printable String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format(
"%02X%s", mac[i],
(i < mac.length - 1) ? "-"
: ""));
}
// print the final String containing the
// MAC Address
//System.out.print(sb.toString()+",");
stMac = stMac+ sb.toString()+"," ;
}
}
}
catch (SocketException e) {
e.printStackTrace();
}
return stMac;
}
public static String getMacWindow() throws SocketException, UnknownHostException
{
// create a variable of type NetworkInterface and
// assign it with the value returned by the
// getByInetAddress() method
String machinMacAdress = "";
InetAddress addr = InetAddress.getLocalHost();
// instantiate the MACAddress class
//MACAddress obj = new MACAddress();
//System.out.print("MAC Address of the system : ");
// call the getMAC() method on the current object
// passing the localhost address as the parameter
NetworkInterface iface
= NetworkInterface.getByInetAddress(addr);
// create a byte array and store the value returned
// by the NetworkInterface.getHardwareAddress()
// method
byte[] mac = iface.getHardwareAddress();
// convert the obtained byte array into a printable
// String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format(
"%02X%s", mac[i],
(i < mac.length - 1) ? "-" : ""));
}
// print the final String containing the MAC Address
//System.out.println(sb.toString());
machinMacAdress = sb.toString() ;
return machinMacAdress;
}
public static String getMacWindow2() {
InetAddress ip;
String myMacAdress = null ;
try {
ip = InetAddress.getLocalHost();
System.out.println("IP address : " + ip.getHostAddress());
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
System.out.print("MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
System.out.println(sb.toString());
myMacAdress=sb.toString() ;
} catch (Exception e) {
e.printStackTrace();
}
return myMacAdress;
}
}
October 12, 2022 - 7:47 am UTC
SQL Reference
A reader, October 12, 2022 - 11:22 am UTC
I don't know how to create this java class
CREATE JAVA