MonthDecember 2010

How to get MAC address in Java

Since JDK 1.6, Java developers are able to access network card detail via NetworkInterface class. In this example, we show you how to get the localhost MAC address in Java.

Example : Get MAC Address via NetworkInterface.getByInetAddress()


This NetworkInterface.getHardwareAddress() method is only allow to access localhost MAC address, not remote host MAC address.

Old day…

Before JDK1.6 is released, many are using command and pattern to get the MAC address in Windows, minor code changes will enable it to get the MAC address in *nux as well.

Example : Get MAC Address via command & pattern


This obsolete method is not really efficient, because it does not display which MAC address is using now, what it did is just print out all the available MAC address currently attached. However, it’s nice to share here.

How to get IP address in Java

To get IP address of the current computer that’s running the Java application, uses InetAddress.getLocalHost() to initialize the InetAddress object and InetAddress.getHostAddress() to get the current IP address.

Full example.


IP is my computer’s IP address to run this example, let compare with Ubuntu’s ifconfig

ifconfig output…

Same, InetAddress.getHostAddress() is working as expected.

Application Authentication with JAX-WS

One of the common way to handle authentication in JAX-WS is client provides “username” and “password”, attached it in SOAP request header and send to server, server parse the SOAP document and retrieve the provided “username” and “password” from request header and do validation from database, or whatever method prefer.

In this article, we show you how to implement the above “application level authentication in JAX-WS”.


On the web service client site, just put your “username” and “password” into request header.

On the web service server site, get the request header parameters via WebServiceContext.

That’s all, now, your deployed JAX-WS is supported application level authentication.

Authentication with JAX-WS Example

See a complete example.

1. WebService Server

Create a simple JAX-WS hello world example to handle the authentication in application level.

File :

2. EndPoint Publisher

Create an endpoint publisher to deploy above web service at this URL : “http://localhost:9999/ws/hello”

File :

3. WebService Client

Create a web service client to send “username” and “password” for authentication.

File :


4. Tracing SOAP Traffic

From top to bottom, showing how SOAP envelope flows between client and server.

1. Client send request, the username “cazo” and password “password” are included in the SOAP envelope.

2. Server send back a normal response.


Ubuntu May Replace GDM with LightDM

Yet another possible change in Ubuntu’s core components: they’re mulling over replacing GDM with LightDM. Why? Well: “Faster – the greeter doesn’t require an entire GNOME session to run. More flexible – multiple greeters are supported through a well defined interface. This allows Ubuntu derivatives to use the same display manager (e.g. Kubuntu, Lubuntu etc.). Simpler codebase – similar feature set in ~5000 lines of code compared to 50000 in GDM. Supports more usecases – first class support for XDMCP and multihead.”

Linux: Executando comandos em looping no shell

Como fazer o seu shell ficar rodando um comando qualquer sempre?  Utilizando os laços while e until.

Para o shell executar o comando “netstat -nat” a cada um segundo podemos fazer o seguinte:

$ while true; do netstat -nat; sleep 1; clear; done;

Esse comando executa “netstat -nat” enquanto a expressão true for verdadeira, como a expressão true SEMPRE será verdadeira, o laço se repetira infinitamente.
Com isto podemos executar qualquer comando, fica a critério do usuário e isto também não impede o uso de auxiliares como o “pipe” (|) ou “&&”.#

Também podemos fazer a mesma coisa com o comando until:

$ until false; do netstat -nat; sleep 1; clear; done;

Da mesma forma que o exemplo anterior, este laço repetirá o comando infinitamente enquanto a expressão false for falsa.

© 2017 Ziben IT Solutions

Theme by Anders NorénUp ↑