Find IP and Mac Addresses of LAN Network without subnet - java

I want to develop a software, my proper way is JAVA, It sounds simple, but has its own problems.
I have a Network in which there are some devices ( about 400 radios or more)
I do not know their IP.
I just know the first and second part of their MAC addresses.
I want to find out their IP and the whole Mac address of all.
They are in my network, and i have forgotten their IP, and also MAC.
I found this Link useful, but in this solution it is about remote connection to nmap and also you should known the range of IP.
Note that this not about HACKING Or better to say is not about CRACKING or something like this, I have thousands of Radio's and they have been reset and need to be re-config.
Actually i need their MAC to config more than IP.
There are other questions on the net, but they are about having subnet, I do not have subnet of the LAN Network.
Now i am looking for any solution with java or other programming languages, with ARP or dd-wrt something like that, any suggestion? or any solutions? Any sample?
I appreciate this.
Thx all.

If this is your network, inspect ARP tables form network devices. You get all MAC addresses and corresponding IPs. Use SNMP protocol and corresponding libs to get this data form your Java code.
To test this approach use snmpwalk utility.

Related

How to get IP's of all network devices in Java

I'm working on a project, and basically I need this program to find a list of all connected IP addresses to a network, such as going to your network connections in Windows. I've looked all over the internet, and I cant find what I'm looking for and I hope someone can!
This program cannot just crunch numbers (such as pinging all possible IP addresses), it needs to be faster than that. Being able to just connect to the network and obtain a "list" of all IP's that it can see would be perfect. Using the docs.oracle.com webpage did what it was supposed to, but there were too many extra results (including Eth10, etc). Also, the only IP address it listed that wasnt my own didnt match any active computers, so I dont know what was up with that... (192.168.0.9 was listed, the only other active connection was at 192.168.0.10, maybe I'm missing something?).
What is a way to do this? Sorry if I'm unclear, I'm able to be clearer if there's something specific, hope this helps!
Thanks!
EDIT: I hope this helps; I want to do this in java, because for my designed program to work it needs a list of active IP addresses connectable to the active machine. Meaning that if I run it on a laptop at a school, I need all the IP addresses that I could connect to on the network. It is a network thing, but it does need to be done in java. The purpose is for a file manager, otherwise its pretty tough to explain. Does that help?
The only way to do what you are asking is via brute force. It can be done somewhat quickly by creating multiple threads that fire off TCP SYN requests to random IPs on the network (this is what NMap does). If you had access to the DHCP server then you could likely get a list from that point. I would warn you to tread very lightly. Running NMAP or doing port scans on a network is considered an attack by many network admins... you could get yourself in to trouble (they WILL notice).

How to efficiently network an application in Java

I was wondering if someone could give me a clue. The situation is we have one computer that has a server application, the rest have a client application. Now my question is how would i keep track of the server ip address? What I want is have the clients automatically hunt the server application, regardless of the ip address and find it, because using a wireless network computers are using DHCP. So I was wondering is there anything that can be buried in a computer using Java with which other computers can identify the application. Thanks.
The "good" way is to use DNS (imho the ONLY solution in a productive environment), as #Peter Lawrey already mentioned, and i would prefer that solution.
You have two other possibilities:
Let the server broadcast his address on the network.
Let the clients scan the network.
Both this solutions are not ideal, because you create a lot of noise on the network, may be blocked by a firewall, etc. Therefore, i really suggest you to use DNS.
If you can not use the DNS solution i would go with a solution that lets the clients search for the server.
Take a look at this SO question, might get you started.
If they're on the same physical network, your server can broadcast its IP address via UDP to the broadcast address for that sub net.
You could even follow the uPnP standard.
Alternatively, you could host the location of the server from a known other location, like a web server. For example, call an action on the known web server to retrieve the IP address of the server. This allows you to utilize DNS to look up the first host, then go from there.
If you know the DNS-Name of the server you can use that name instead of the IP. Java takes care of the DNS lookup.
Otherwise, I guess the simplest solution is just to scan the IP range of your network and just try to connect to each IP and test if it works.
Other solutions would include broadcasts by the server and would be much more complicated and maybe overkill for a application hosted in a small network.

How to differentiate online IP Address from Local IP/Other Machine IP on LAN in Java

Is there any possible way to differentiate online IP Address from Local/Other Machine IP on LAN in Java?
I am working on a application, there is a need to identify the Local IP/LAN IP and Online IP address input by user.
Thanks in advance.
As far as I am aware, there is no way to do this based solely on the IP (and that is not specific to Java, but based on the way networks work).
If you have additional information, however, you may be able to do this. There are three networks of IP addresses that are not used on the internet. Those are:
10.0.0.0/8
172.16.0.0/12
192.168.0.0/16
If you know the LAN IP addresses will be from specific ranges (including the network the host is in on which your application is runnning), you can differentiate; however - and do not try this at home kids since it will give you headaches - if you use IP addresses in your LAN that are also used on the internet, you will not only have address conflicts, but also trouble to distinguish between online and LAN IPs.
Something else though; if your users try to "connect" via the internet, but are behind a NAT, your application will only see the source of their traffic as the public IP of the gateway doing the NAT for your users. So, for example, if two of your users are somewhere in a LAN with IPs from 10.0.1.0/24, but their gateway has a public IP of 123.123.123.123, your application will see BOTH users as having the IP 123.123.123.123
You might have to come up with a different way of authentication if you intend to use this in a way similar to VPN, or you have to know all the public IPs of all gateways of all of your users who are behind NATs.
A note on terminology, as Marcelo pointed out: afaik, "online" and "offline" are not terms usually used with IPs. We rather speak of "public" (the ones seen on the internet) and "private" IPs (those within your own network noone on the internet can see).
You can get the external IP using some API such as http://automation.whatismyip.com/n09230945.asp. If you can reach that API and get the IP, you are "online" - i.e., connected to the internet. If you can't, you are "offline" (unless the host is down, etc).
If you need the local host, you can use
InetAddress thisIp =InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress())
Please clarify what you consider an "offline IP address", as I've never heard of such concept before.

How to discover all the available IP addresses of the web-server?

How to detect ( discover ) all of the web-servers by using j2me ? I mean that the web-servers are inside a LAN.
I assume you are not interested in asking every IP address or named host from the list hard-coded into an app.
You may find Zeroconf protocol useful. It is suited for discovering of available services with the means of broadcast or multicast IP packets.
Debian Wiki page has some links to Zeroconf software, including libapache2-mod-dnssd.
As for client part, maybe this will help: Are there any other Java libraries for bonjour/zeroconf apart from JMDNS?

How do I send data between two computers over the internet

I have been struggling with this for the entire day now, I hope somebody can help me with this.
My problem is fairly simple: I wish to transfer data (mostly simple commands) from one PC to another over the internet.
I have been able to achieve this using sockets in Java when both computers are connected to my home router. I then connected both computers to the internet using two different mobile phones and attempted to transmit the data again. I used the mobile phones as this provides a direct route to the internet and if I use my router I have to set up port forwarding, at least, that is how I understand it.
I think the problem lies in the method that I set up the client socket. I used:
Socket kkSocket = new Socket(ipAddress, 3333);
where ipAddress is the IP address of the computer running the server. I got the IP address by right-clicking on the connection, status, support. Is that the correct IP address to use or where can I obtain the address of the server? Also, is it possible to get a fixed name for my computer that I can use instead of entering the IP address, as this changes every time I connect to the internet using my mobile phone?
Alternatively, are there better methods to solving my problem such as using http, and if so, where can I find more information about this?
EDIT:
Would it be possible to have the server program running on a server on the internet somewhere. My original server would then be a client that send information to this server. This server would then pass this information to my original client and vice versa. That way, the IP address of my computer won't matter, as I only need to know the address of the server hosted somewhere on the web. Does this seem like a better solution? Where do I begin implementing such a solution?
Thanks!
When you connected to the server that serves StackOverflow, did you type in the IP address? It's 64.34.119.12, if that jogs your memory.
You probably didn't. You probably typed "stackoverflow.com". There's a huge, complex, clever, and in some ways, poorly implemented system called DNS that translates sensible and human-readable names into IP addresses.
One problem with DNS, though, is you need a "static IP", which is exactly what it sounds like: an IP address that doesn't change, which is exactly what you don't have.
So, what can you do?
You can buy a static IP account from your ISP (pretty expensive)
You can use some proxy out in the Internet (a machine that does have a static IP and is willing to bounce your packets back and forth -- I'm not aware of any service that does this for you; you could write one and put it up on Amazon Web Services or Google App Engine, both of which would be free at your level of usage, but they'd be slow, since every packet trying to cross your living room would have have to go via some data-center in Virginia).
You can keep doing what you're doing, looking in the net-configuration of your machine.
You could speed (3) up a little by having your server program look up its own IP address and print it out where you could see it and type it into the server by hand.
You can use DynDNS, as Sergey mentioned (this is the "right" solution, in that it's very general, it just might be a little complicated to set up)
You can use multi-casting.
Multi-casting is an interesting solution, and it may work for you. The idea is, when your server starts up, it announces to the net, "Here I am, I'm providing X server, here's my IP address, talk to me." The problem is, a multi-cast won't leave your living room. Obviously, if every multi-cast were spread to every computer on the Internet, the whole thing would collapse, so your router will ignore, and not route, multi-cast packets. That may or may not be a deal-breaker for you. EDIT Re-reading your question, I see it is a deal-breaker for you. I'd go with #5, but be aware there may be routing issues (address translations that prevent a server from knowing the address that other computers can find it at) or fire-wall issues (that is, your ISP may prevent your server from receiving incoming packets even if the address is correct).
using a direct socket connection with a port like 3333 is usually complicated because different network configurations.
firewalls will make a pleasure preventing the connection, or killing it from time to time.
maintaining a 2-way connection can be a nighmare. the SIP protocol is struggling with this kind of problems.
For a simple application, i suggest you look into the comet technology, where your clients can establish an http connection with a shared server. The server can then bridge commands between them.
html5 will also bring the websocket protocol to the table.
I got the IP address by right-clicking
on the connection, status, support.
Not sure about the "support" part, and I'm not on a Windows machine right now, but I think that the most easy and reliable way to figure out the IP address on Windows is to run "ipconfig" from the command line (Win+R, type "cmd", then "ipconfig" in the opened window). This, of course, should be done on the server side.
However, the problem is that depending on the ISP your IP address may be not within the Internet, but within a local ISP network (so-called NAT). In this case, you'll need to use some sort of black magic called TCP hole punching, which is very complicated and not guaranteed to work. You can figure out if your address is local or not by looking at it. For IPv4 local addresses are almost always like 10.x.x.x or 172.16-31.x.x, or 192.168.x.x. Don't know about IPv6.
You can also check your IP by visiting one of the special sites like www.whatismyip.com. If the address they tell you is different from the one you see by running "ipconfig" or looking at the connection properties, then you're almost certainly behind a NAT (or your ISP is using a transparent proxy, but that's rare).
If you are directly connected to Internet (no local addresses and NAT), then you should also check if you have any firewall software and either to configure it to allow connections to the port you use, or make sure it's in "ask the user" (and not "silently reject") mode, or just disable it completely (this may put your computer at risk, especially if there is no anti-virus software or the system isn't up-to-date).
Also, is it possible to get a fixed
name for my computer that I can use
instead of entering the IP address, as
this changes every time I connect to
the internet using my mobile phone?
Yes, it's possible. There is the thing called DynDNS, and there are DynDNS providers like DynDNS.com, where you can get a third-level domain name for free (like mycoolpc.dyndns.org). You'll have to install and configure some DynDNS client on your PC that will tell the DynDNS server its new IP each time each changed. I don't know anything about particular clients to use because I'm using the one built-in in my home router.
No need to write networking code for this, unless it really floats your boat. Take a look at SCP. http://amath.colorado.edu/computing/software/man/scp.html. There is a windows implementation where you can download putty (windows ssh client), and it is on most linux distributions. Alternatively, you could set up an FTP or SSH server on one or both of the machines.
"a fixed name for my computer that I can use instead of entering the IP address" would be a domain name, these are purchasable online for a few bucks.

Categories