getting os name, ip address, mac address in java - network-programming

How can I get OS name, IP Address, and Mac Address of remote host in same local area network using java.I have tried arp -a and nmap -O but it's not reliable . It does not work on windows.

Get OS name:
System.getProperty("os.name");
Get IP:
InetAddress.getLocalHost();
Not sure what you mean by 'Mac Address'

Related

DOCKER: Linux Container on Windows 10, how to use nmap to scan device's mac address

I am trying to setup the docker which can successfully scan the subnet device's mac address by using nmap. And I've spent 3 days to figure out how to do it but still failed.
For example:
The host IP: 10.19.201.123
The device IP: 10.19.201.101
I've setup docker container which can ping 10.19.201.123 and 10.19.201.101 both successfully. But when I use nmap to scan mac address from docker container, I got below:
~$sudo nmap -sP 10.19.201.101
Starting Nmap 7.01 ( https://nmap.org ) at 2018-05-29 08:57 UTC
Nmap scan report for 10.19.201.101
Host is up (0.00088s latency).
Nmap done: 1 IP address (1 host up) scanned in 0.39 seconds
However, if I use nmap to scan mac address from VM (10.19.201.100), I got:
~$sudo nmap -sP 10.19.201.101
Starting Nmap 7.01 ( https://nmap.org ) at 2018-05-29 17:16 CST
Nmap scan report for 10.19.201.101
Host is up (0.00020s latency).
MAC Address: 0F:01:H5:W3:0G:J5(ICP Electronics)
Nmap done: 1 IP address (1 host up) scanned in 0.32 seconds
PLEASE, who can help or give prompts of how to do it?
For who is still struggling with this issue, I've figured out how to do it on Windows 10.
The solution is to make the container running on the same LAN as your local host, so nmap can scan the LAN device successfully. Below is the way to make your docker container run on the host LAN.
Windows 10 HOME
Change the virtual box setting
Stop VM first by administrator docker-machine stop default
Open Virtual Box
Select default VM and click Settings
Go to Network page, and enable new Network Adapter on Adapter 3
(DO NOT CHANGE Adapter 1 & 2)
Attached Adapter 3 to bridged Adapter with your physical network and click OK
Start VM by administrator docker-machine start default
Open Docker Quickstart Terminal to run container, the new container should be run on the LAN now.
Windows 10 PROFESSIONAL/ENTERPRISE
Create vSwitch with physical network adapter
Open Hyper-V Manager
Action list- > Open Virtual Switch Manager
Create new virtual switch -> select Type: External
Assign your physical network adapter to the vSwitch
Check "Allow management operating system to share this network adapter" and apply change
Go to Control Panel\All Control Panel Items\Network Connections.
Check the vEthernet you just created, and make sure the IPV4 setting is correct. (sometimes the dhcp setting will be empty and you need to reset again here)
Go back to Hyper-V Manager, and go into Setting page of MobyLinuxVM (ensure it's shut down, if it's not, Quit Docker)
Add Hardware > Network Adapter, select the vSwitch you just created and apply change
Modify Docker source code
Find the MobyLinux creation file: MobyLinux.ps1
(normally it's located at: X:\Program Files\Docker\Docker\resources)
Edit the file, and find the function: function New-MobyLinuxVM
Find below line in the function:
$vmNetAdapter = $vm | Hyper-V\Get-VMNetworkAdapter
Update it to:
$vmNetAdapter = $vm | Hyper-V\Get-VMNetworkAdapter | Select-Object -First 1
Save file by administrator
Restart Docker, and the container should run on the LAN now.

Portforwarding not working

I recently tried to portforward port 80 on my local IP, but as the tutorial said, it should be open on my external IP, which it's not. But it is open on my local ip thought.
I have portforwarded port 80, range 80 UDP and TCP on my local IP: 192.168.1.170
This is the tutorial i followed: https://www.youtube.com/watch?v=RZTYqTGqtjI
I portforwarded my IP in the router settings.
https://image.ibb.co/hGW4fm/Sk_rmbild_345.png
https://image.ibb.co/exWFmR/Sk_rmbild_344.png
IF THE suggested METHOD DOESN'T WORK FOR YOU , DO THIS :-
GOTO -> SECURITY TAB -> REMOTE MANAGEMENT
Enable the Remote Management (or enter 255.255.255.255 in the field) .
This will enable the you to access your LAN from WAN.
For the record :-
Internal Port is the PORT on which the device in your LAN is serving .
External Port is the port which the user enters in the browser . exp :- 127.184.184.19:8080 .
Here 8080 is the external port . And if a device in your LAN runs a http web server at port 80 , then the internal port would be 22.
If the Above methods don't work , then your ISP might be using Carrier NAT which means you would have a different PUBLIC and WAP ip address .
In this case , you should use the WAN ip address shown in your router configuration page to access your LAN from internet. s
Kindly Try to open same URL from different Internet Connection other than LAN

NSLOOKUP to iOS 9 device can't find host name

[Updated]
I want to get an iOS device's host name by ip address from command line
I think I can use NSLOOKUP tool on Mac, but I'm getting
nslookup 10.0.1.2
Server: 8.8.8.8
Address: 8.8.8.8#53
** server can't find 2.1.0.10.in-addr.arpa.: NXDOMAIN
The 10.0.1.2 is ip of an iPhone.
Is there any special on iOS for DNS host name resolution?
I think this may be what you are looking:
Swift:
UIDevice.currentDevice().name
ObjC:
[[UIDevice currentDevice] name];
Thanks

How to enable docker remote api in mac OS X?

I'm new to docker, and I want to use java api to print my docker information. I read this tutorial.I use boot2docker and print this command "boot2docker ip" to find my docker machine ip is
bash-3.2$ boot2docker ip
192.168.59.103
So,I use rest to connect docker.I input http://192.168.59.103:2376/info
and it can connect to it,but show nothing.So I guess it maybe I should make my docker enable rest. How should I do for it? I'm also new to mac OS X. please give more detail for me. Thanks
I use command:
curl -v http://192.168.59.103:2376/info
it show information :
* Hostname was NOT found in DNS cache
* Trying 192.168.59.103...
* Connected to 192.168.59.103 (192.168.59.103) port 2376 (#0)
> GET /info HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 192.168.59.103:2376
> Accept: */*
>
* Connection #0 to host 192.168.59.103 left intact
As mentioned in "Enabling Remote API in Docker on Mac OS X (boot2docker)", boot2docker supports remote access on port 2375 (non-TLS, instead of 2376 TLS), so try:
http://192.168.59.103:2375/info
More generally, follow Boot2Docker on Mac, for example "from your command line"
boot2docker init
boot2docker start
boot2docker shellinit
eval "$(boot2docker shellinit)"
docker run hello-world

Vagrant ping or curl from guest to host machine

I wonder how I can run the command, using the terminal, from my vagrant machine:
$ ping localhost:3000
or
$ curl http://localhost:3000
In host machine (OSX) I have a rails server running in localhost:3000, so I expect something to show in the rails log.
When I run in the VM:
$ ip route show
In the output there is a line like:
default via 10.0.2.2 dev enp0s3 proto static metric 1024
That is the IP to ping from the guest:
curl http://10.0.2.2:3000
Inside the vagrant machine localhost refers to the guest vagrant machine, i.e. localhost doesn't refer to host machine. One way to access host machine from guest is to configure a private network. You can specify a static private IP for vagrant, like this:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
After this guest is accessible from host via 192.168.50.4 and host is accessible from guest via 192.168.50.1, i.e. the end octate for host's IP will be 1 inside guest machine.
After vagrant up, you can do this from inside guest machine:
$ ping 192.168.50.1
$ curl http://192.168.50.1:3000
Note that, if you have some strict firewall setup then you have to allow connection from 192.168.50.4.
You can also set network to "public_network" in the guest machine's config file.
In the Vageantfile just uncomment the line:
config.vm.network "public_network"
Restart the machine:
vagrant halt
vagrant up
Do the ip addr show and your ip on the public network is the one listed under eth1 (instead of the usual eth0)

Resources