Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: is there a way to get the server MAC address through sql statement ?

Re: is there a way to get the server MAC address through sql statement ?

From: Douglas Hawthorne <DouglasHawthorne_at_yahoo.com.au>
Date: Fri, 27 Feb 2004 21:36:43 GMT
Message-ID: <LLO%b.79122$Wa.11269@news-server.bigpond.net.au>


"srivenu" <srivenu_at_hotmail.com> wrote in message news:1a68177.0402260208.72882f33_at_posting.google.com...
> Try this out.
> I tested it out on 2000 you need to make some changes for Unix.
> I had taken the basic concept from ASKTOM.
>
> create or replace and compile
> java source named "Util"
> as
> import java.io.*;
> import java.lang.*;
>
> public class Util extends Object
> {
>
> public static int RunThis()
> {
> Runtime rt = Runtime.getRuntime();
> int rc = -1;
>
> try
> {
> Process p = rt.exec("arp -a");
>
> int bufSize = 4096;
> BufferedInputStream bis =
> new BufferedInputStream(p.getInputStream(), bufSize);
> int len;
> byte buffer[] = new byte[bufSize];
>
> // Echo back what the program spit out
> while ((len = bis.read(buffer, 0, bufSize)) != -1)
> System.out.write(buffer, 0, len);
>
> rc = p.waitFor();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> rc = -1;
> }
> finally
> {
> return rc;
> }
> }
> }
> /
>
>
> create or replace
> function RUN_CMD return number
> as
> language java
> name 'Util.RunThis() return integer';
> /
>
> create or replace procedure RC
> as
> x number;
> begin
> x := run_cmd;
> end;
> /
>
>
> set serveroutput on size 1000000
> exec dbms_java.set_output(1000000)
> exec rc;
>
> regards
> Srivenu

Srivenu,

The problem with this code is that it returns the wrong answer even if you added extra code to extract the MAC address from the output stream. The "arp -a" command may return some or all of the MAC addresses of the server's neighbours on a LAN segment but not the MAC address of its interface card. If you want to use this method, employ the "ipconfig /all" command for Windows, or the "ifconfig -a" command for Linux.

Niall's solution is better because the only time the MAC address changes is when the hardware changes through a new network interface card (NIC).

A question for the OP: why? I am curious to know the business requirement for such a request.

Douglas Hawthorne Received on Fri Feb 27 2004 - 15:36:43 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US