CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    How to decide if internet or LAN ip?

    I want to know my ip address for internet. I use gethostname() and then gethostbyname() with the result of the first. Now I get a list of all my IPs, but how do I know which one is the internet ip? The only way I can imagine is to check which network class the ip is. Is this a good idea, or is there a better way?
    Please don't forget to rate users who helped you!

  2. #2
    Join Date
    May 2005
    Posts
    47

    Question Re: How to decide if internet or LAN ip?

    but how can you classify them ?


  3. #3
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: How to decide if internet or LAN ip?

    One idea, you know your IP and sub-net mask. Compare the IP's net id with yours ( using mask and IP ). If it is the same you know that it belongs to your subnet. Otherwise it belongs to the outer subnet/network.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  4. #4
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: How to decide if internet or LAN ip?

    Quote Originally Posted by Mathew Joy
    One idea, you know your IP and sub-net mask. Compare the IP's net id with yours ( using mask and IP ). If it is the same you know that it belongs to your subnet. Otherwise it belongs to the outer subnet/network.
    Well, I know my IP but I can't hard code it because it is a multi-user program. And that is also the problem with classification of the IPs:
    Quote Originally Posted by grabbler
    but how can you classify them
    Normally home networks have IPs starting with at least 192. That's because of the class A network ip address range selected by ICANN. That's how I do it now. The problem is: users might not always stick to the ICANN, when selecting their LAN ip.
    Please don't forget to rate users who helped you!

  5. #5
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: How to decide if internet or LAN ip?

    Quote Originally Posted by philkr
    Well, I know my IP but I can't hard code it because it is a multi-user program. And that is also the problem with classification of the IPs:
    Hard coding? Why do you need to hard code your IP?

    See How to get the local IP address(es)? for more details..
    Quote Originally Posted by philkr
    Normally home networks have IPs starting with at least 192. That's because of the class A network ip address range selected by ICANN. That's how I do it now. The problem is: users might not always stick to the ICANN, when selecting their LAN ip.
    Well, 192 IP range belongs to class C.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  6. #6
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: How to decide if internet or LAN ip?

    Quote Originally Posted by Mathew Joy
    Hard coding? Why do you need to hard code your IP?
    Sorry, it seems I misunderstood the first part of your post.
    Quote Originally Posted by Mathew Joy
    Well, 192 IP range belongs to class C.
    Yes, that's what I meant. I got mixed up. However, thanks for the link, I will rate it.
    Please don't forget to rate users who helped you!

  7. #7
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: How to decide if internet or LAN ip?

    Quote Originally Posted by philkr
    However, thanks for the link, I will rate it.
    You don't have to mention it...rating is up to the individual to. Rating or no rating...we are here to help.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  8. #8
    Join Date
    Jan 2011
    Posts
    6

    Re: How to decide if internet or LAN ip?

    you can get your IP Address details, through this site http://www.ip-details.com/ip-search/
    It has the best result about internet service provider,location, country and and also provides the IP details at free cost itself.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured