Java code to listing Network Interface Addresses run on Windows 10

One of the most useful pieces of information you can get from a network interface is the list of IP addresses that are assigned to it. You can obtain this information from a NetworkInterface instance by using one of two methods. The first method, getInetAddresses(), returns an Enumeration of InetAddress. The other method, getInterfaceAddresses(), returns a list of java.net.InterfaceAddress instances. This method is used when you need more information about an interface address beyond its IP address. For example, you might need additional information about the subnet mask and broadcast address when the address is an IPv4 address, and a network prefix length in the case of an IPv6 address. ~ https://docs.oracle.com/javase/tutorial/networking/nifs/listing.html

The following example program lists all the network interfaces and their addresses on a machine (tested on PC running Windows 10):
package javalistinetaddress;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;

public class JavaListInetAddress {

public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets))
displayInterfaceInformation(netint);
}

static void displayInterfaceInformation(NetworkInterface netint) throws SocketException {
System.out.printf("Display name: %s ", netint.getDisplayName());
System.out.printf("Name: %s ", netint.getName());
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
System.out.printf("InetAddress: %s ", inetAddress);
}
System.out.printf(" ");
}

}



Related:
- Java code to listing Network Interface Addresses, run on Raspberry Pi/Raspbian Jessie

Read More..

Retrieve IP and MAC addresses from proc net arp

Last post "Display WiFi Hotspot clients by "cat /proc/net/arp"" display arp as human readable string, but not machine readable. Its another version to retrieve IP and MAC addresses, store in a ArrayList.


MainActivity.java
package com.blogspot.android_er.androidlistclient;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

Button btnRead;
TextView textResult;

ArrayList<Node> listNote;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnRead = (Button)findViewById(R.id.readclient);
textResult = (TextView)findViewById(R.id.result);

listNote = new ArrayList<>();

btnRead.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
readAddresses();
textResult.setText("");
for(int i=0; i<listNote.size(); i++){
textResult.append(i + " ");
textResult.append(listNote.get(i).toString());
textResult.append(" ");
}
}
});
}

private void readAddresses() {
listNote.clear();
BufferedReader bufferedReader = null;

try {
bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"));

String line;
while ((line = bufferedReader.readLine()) != null) {
String[] splitted = line.split(" +");
if (splitted != null && splitted.length >= 4) {
String ip = splitted[0];
String mac = splitted[3];
if (mac.matches("..:..:..:..:..:..")) {
Node thisNode = new Node(ip, mac);
listNote.add(thisNode);
}
}
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally{
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

class Node {
String ip;
String mac;

Node(String ip, String mac){
this.ip = ip;
this.mac = mac;
}

@Override
public String toString() {
return ip + " " + mac;
}
}
}


layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

android_layout_width="match_parent"
android_layout_height="match_parent"
android_padding="16dp"
android_orientation="vertical"
tools_context="com.blogspot.android_er.androidlistclient.MainActivity">

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center_horizontal"
android_autoLink="web"
android_text="http://android-er.blogspot.com/"
android_textStyle="bold" />

<Button
android_id="@+id/readclient"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_textAllCaps="false"
android_text="Read Ip/MAC addresses"/>

<TextView
android_id="@+id/result"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_typeface="monospace"
android_textSize="24sp"/>
</LinearLayout>


Next:
- Lookup manufacturer info by MAC address, using www.macvendorlookup.com API
- Get HostName of WiFi hotspot clients, and check if it is still connected

Read More..

Outlook Imports Email Addresses from Facebook Offers No Takeout

You can easily import Facebook email addresses, birthdays and phone numbers into the userr Outlook address book but there’s no takeout option.

import facebook email address
The new Outlook.com web mail service from Microsoft makes it super easy for user to import contact details from Facebook and LinkedIn into userr address book. It imports birthdays, addresses, phone numbers (from LinkedIn) and also the email addresses of userr Facebook friends.
If user haven’t had a chance to try this yet, go to outlook.com and switch to the People tab (see video demo below). Now choose “Add People” from the “Manage” menu and choose Facebook from the list of available options.
Outlook will now import userr Facebook friends details into userr address but this data won’t include their email addresses. Open the “Add People” menu again and now user will see an option to import Facebook email addresses.
Outlook is a one-way street
This is useful because user can export userr Outlook address book as a CSV file and import it into other systems like Gmail but there’s one big limitation.
Outlook will not let user export any data that was auto-imported from a social network network like Facebook, Twitter or LinkedIn. You can see the imported email addresses, phone numbers and birthdays of contacts inside Outlook.com but user can’t take this data out to another service at least yet. If user add any custom data to an auto-imported contact, that data will however be included into the CSV file.
Fortunately, there’s Yahoo! Mail that does allow quick export of Facebook email addresses.

Video – Import Email Addresses from Facebook


Read More..

Blog Archive

Powered by Blogger.