• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Relation between Host file & java.net.* ?

 
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In hosts file i found following entries:-


in ifconfig i can see my pc ip address is 10.212.11.228 & Mac Address = 00-18-FE-64-5C-37

For Finding Mac Address of PC by programming i use 2 different java programs & test 4 cases
1. host file remain as it is.
2. In host file only active 1 line which has 127.0.0.1 other line inactive by #, restart network service
3. In host file only active 2nd line which has 10.111.17.3 other line inactive by #, restart network service
4. In host file all lines inactive by #, restart network service

Code 1:-

Results of test cases:-
Code 1, Test 1 output in console:-

Code 1, Test 2 output in console:-

Code 1, Test 3 output in console:-

Code 1, Test 4 output in console:-


code 2:-

Results of test cases:-
Code 2, Test 1 output in console:-

Code 2, Test 2 output in console:-

Code 2, Test 3 output in console:-

Code 2, Test 4 output in console:-


My question is what is relation between host file which present in Linux or Windows & java.net.* ?
If what ever i do change for test above test case, in ifconfig result no changes.
I try to google also but not getting proper way.
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where do you see a connection between the hosts file and the code? In other words, what (and why) did you expect to change?
 
Mandar Khire
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In network setting i keep 'Automatically obtain IP address setting with dhcp' when i test above 2 codes.
in ifconfig i can see my ip address 10.212.11.228 & Mach address 00-18-FE-64-5C-37

But then also i write in host file following line
10.111.17.3 dtp016.galaxy.in
to check that ip.getHostAddress() read original IP address or which i write static address which not actually set in network setting.
Rest of the things i write previous post.
My aim is to
1. understand importance of host file
2. understand how my 2 codes works actually.

Why java program give me ip address 10.111.17.3 when i keep inactive 127.0.0.1 in host file but ifconfig command give me proper ipaddress which is set automatically?
How i can write program like ifconfig which always give me right answer?
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For starters, the MAC address is not relevant - it is related to the hardware you're using, and is not changeable.

I looked briefly at the two codes, and they look similar - what is the difference between them?
 
Mandar Khire
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The result related to Mac address
i got with code1 in test 1 & test 3 but

with code 2 any test case i got same result.
(It print mac address at while loop 1st time & mac is null in 2nd time).
That is the only difference i found.
Why code 1 not give me mac address in each test when

For starters, the MAC address is not relevant - it is related to the hardware you're using, and is not changeable.



In test 1 & 3 i do changes in host file which i mention previous post.
for test 1 host file as below:-


for test 2 host file as below:-


for test 3 host file as below:-


for test 4 host file as below:-


So i think there is something relation between host file with these 2 codes.

when i closely look my code 1 i see declaration

it initialize as below

used for getting Hardware Address


Related to NetworkInterface.getByInetAddress(ip) i found java doc

So question comes why specified address is null?

in code 2 used

it initialize as below:-


related to this i got java doc:-


1 more thing i try to understand after lot of searching...
I am using CentOS in that
/etc/sysconfig/networking/profiles/default
i found 5 files
1. hosts (it is same which found in /etc)
2. ifcfg-eth0 it contains following:-

3.network which contains following:-

4. resolve.conf it contains auto generated text when i choose 'Automatically obtain IP address settings with dhcp'
when i use static ip address i keep empty that file other wise pc get slow.
5.route-eth0 which contains as follows:-
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic