Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Server IP address

Posted on 2003-03-09
11
Medium Priority
?
340 Views
Last Modified: 2010-04-21
Hello Experts,
  Can anyone please give me the idea or code to get the server ip address.
Is there any inbuilt function. And later i would like to convert it into hexa and use it.
please do get back to me on this immediately.
Regards
Deepika
0
Comment
Question by:Deepikak
  • 4
  • 3
  • 2
  • +1
11 Comments
 

Author Comment

by:Deepikak
ID: 8101125
FYI
 I am coding in C++ and for the above mentioned i should be able to get something like
cae83f21   for the ip adress  202.232.63.33
Thanking you
Deepika
0
 
LVL 21

Expert Comment

by:tfewster
ID: 8101864
Which Unix? You can try:
grep `hostname` /etc/hosts
ifconfig -a  (man ifconfig, if your OS does not have the -a option)
0
 
LVL 21

Expert Comment

by:tfewster
ID: 8101882
Oh, and `netstat -in`; This should work with any Unix.

Your code may need to check if there is more than one IP address (E.g multiple NICs or multiple addresses bound to one NIC)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Gns
ID: 8137420
I think Deepikak means from c/c++ tfewster.

You should probably be looking at the manpages for gethostbyname, gethostent, ntohl, ntohs, htonl and ntohs.

-- Glenn
0
 
LVL 5

Accepted Solution

by:
cryptosid earned 80 total points
ID: 8730756
hey deepika

good to see an indian unix programmer....

check this page:http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?gethostbyname+3
0
 
LVL 20

Expert Comment

by:Gns
ID: 8730883
Thanks for providing a link to an incarnation of the manpage deepika should read (as I already mentioned;). Deepika should be reading his own systems manpage though, since any idiosyncrasies(sp?) are probably more likely to be documented there.

Also note that all this will get him/her is a long (or rather h_lenght (number of bytes) address) in network byte order, which he/she will then need convert to host byte order with ntohl, and finally (with some muckery, or just through simple printf's:-) to a string representation in hex (or... as said, just display it as hex).

-- Glenn
0
 
LVL 5

Expert Comment

by:cryptosid
ID: 8731041
chill dear Glenn ... i just happened to know these pages so i pasted the link... i guess deepika is intelligent enough to understand the complications involved.....each one of us is learning over here arent we...oops but one thing we won't learn here is to 'inculcate some politeness....' anyways kudos to u

Chill Glenn Chill
cryptosid
0
 
LVL 20

Expert Comment

by:Gns
ID: 8731103
Hey, I'm not trying to be impolite... Just a bit correct:-). And he really should be reading his own systems manpages, since the implementation of this part actually do vary... And since this qestion had been "dormant" for three months, I figured... If I was going to post anyway, why not spell it out:-).

Since it's raining here in Stockholm, I'm very much chilled down indeed (_not_ frosty;-).
In fact, I was never "heated up" at all.
Since I'm lacking my english dictionary, you might illuminate me as to the word "inculcate"... never heard that one (as one can guess from my location, I'm not a native to english).

-- Glenn
0
 
LVL 5

Expert Comment

by:cryptosid
ID: 8731725
ha ha ha...i mistook u for a rude all knowing expert...since you are hailing from stockholm i don't think your english is weak by any chance......good sense of humour u got....

for your kind reference:
http://dictionary.reference.com/search?q=inculcate

good to meet u
cryptosid

0
 

Author Comment

by:Deepikak
ID: 8736960
Hello
   I am sorry for this late response. I know this was posted by me long back and that I dint windup this question on the form. (Mr. cryptosid,  you helped a great deal in my learning phase).
My apologies for the inconvenience caused.
Regards
Deepika.
0
 
LVL 5

Expert Comment

by:cryptosid
ID: 8737660
anytime lady anytime...thanks for the points
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question