473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Correct IP Address

144 New Member
hello,

i'm developing a J2SE VoIP app. i used the InetAddress.get LocalHost() to get the address of the local machine.

it works in xp, but not in Ubuntu. in Ubuntu it gives me "127.0.1.1" , which is listed in /etc/hosts file.

after some search, some advice to use

Expand|Select|Wrap|Line Numbers
  1. NetworkInterface.getNetworkInterfaces();
to get list of the available interfaces. but when i println

Expand|Select|Wrap|Line Numbers
  1. NetworkInterface iface = en.nextElement();
  2. System.err.println(iface.getInterfaceAddresses());
i get this output

Expand|Select|Wrap|Line Numbers
  1. [/fe80:0:0:0:216:36ff:feac:d855%2/64 [null], /192.168.1.2/24 [/192.168.1.255]]
the mac address, then the ip address. how to get only the "192.168.1. 2" part?

i've tried using
Expand|Select|Wrap|Line Numbers
  1. iface.getInetAddresses()
but i get the following output
Expand|Select|Wrap|Line Numbers
  1. java.net.NetworkInterface$1checkedAddresses@1884a40
another consideration is, which interface address should i use? i can check if it's a loopback interface since NetworkInterfac e has the isLoopback method.

but sometimes, a machine has two or more NIC with one connected to the local network and the other one to the internet. if the user chooses to connect to a local server, i should choose the interface connected the LAN. and the same thing apply if the user wants to connect to a public server in the internet, i should choose the address connected to the internet.

how to determine this?

Thank you.
Dec 11 '09 #1
1 2967
chaarmann
785 Recognized Expert Contributor
@thesti
Why not use a regular expression to grab it from this String?
Dec 15 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

53
4526
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document, and at the end there is even pure mindstorming text left in, but already I think it can be very useful. <url:...
5
1229
by: lasek | last post by:
Hi all, i have a trouble understanding this: example: #include.... char * testA(void); char * testB(void);
9
2506
by: nsj | last post by:
I am working with a web applicaction that accesses a SQL Server database. I need the value of the 'id' column of the last inserted row in the table 'PERSON'. The SQL statement for that purpose is: "SELECT IDENT_CURRENT('PERSON')"; . I need to insert this value in another table called 'ADDRESS'. So I did the following: ...
3
1571
by: martinharvey | last post by:
This is probably a very simple question but i would appreciate some help with the correct syntax for and update stored procedure I have created a user form that allows the user to update the name and address fields in a datatable called customers based on the input value customer ID = ( datatable/Customers)customerID I have got this...
9
1501
by: sumit1680 | last post by:
Hi all, recently i tried the following peice of code in gcc int main () { char *ptr = "possible"; printf("%s",ptr); return (0); }
5
1924
by: Ben Fidge | last post by:
When using Server.Transfer, the calling page name is still displayed in the browser address bar, as opposed to the called page. This is really confusing my customers! Is there a way round it? Ben
1
2156
by: DaTurk | last post by:
Hi, I want to to find the Mac address of the NIC being used by a given process using a corresponding IP address. It should be pointed out that the machines that this program will be running on will be using more then one NIC. SO I have to use the IP adress to get the correct MAC. Here is the code I'm using to get the IP. Any help would...
1
2579
by: kang jia | last post by:
hi currently i am editing signup page, when user enter deupicated NRIC and click signup, they will go to do_signuppage and read the error message and then after 5 seconds, they will be redirected to signup page again, however, this time they go back, all the correct value will be remain. how should i achieve this. my current code for...
1
3216
by: kang jia | last post by:
hi when user entered particulars in signuppage and click" signup" button, i will direct them to do_signup.php. if say the NRIC is dupicate in datebase, i will redirect them back to signup page again to re-signup, however, i would like to remain all the correct infromation, and let users re-entered their NRIC. how can i do this. can i use...
6
1829
by: jt | last post by:
#include <stdio.h> void f(); int main() { long int i; i=20; f(); i = 10; printf ("\n%d\n",i);
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.