Ipaddress (C#)

Eran

Member
Joined
Apr 12, 2003
Messages
69
Ipaddress

Hi, i am tring to get IPaddress of my machine.
So far I made it. the problem is, I get 2 IPs. One IP is the local Area connection and the other is the PPP adapter.
How do I get the PPP adapter?
 
How to Get IP assigned by RAS

This is the same problem i am facing, i am developing an application in which i want to check the IP address which is assigned by the RAS server ,
but i am unable to do so coz when i try to resolve the

localhost it returnes 127.0.0.1 but in case of this

Code:
 System.Net.Dns.Resolve(SystemInformation.ComputerName)

it returns me 192.168.0.2 which i my currently IP with network card.


Is there any way to check which IP address assigned by Romote Access Server ?
 
Re: How to Get IP assigned by RAS

Madz, this is the code to obtain the Loacal Machine IP.

Code:
using System;
using System.Net;

    static void Main(string[] args) {
      string machine_name = Dns.GetHostName();
      IPHostEntry host = Dns.GetHostByName(machine_name);

      for (int i=0; i < host.AddressList.Length; i++){
        Console.WriteLine(host.AddressList[i]);
      }
      Console.ReadLine();
    }

host.AddressList[0] is the Local Area Connection IPaddress.
host.AddressList[1] is the PPP IPaddress.
You can use the host.AddressList[1] but can you be sure that in all of the machine youll get the PPP IPaddress in the second field?
I am not. If theres other way to write in the code that the computer will give you only the PPP.
 
THanks for you help dear
Actually my application is that type when ever my application starts it should check Ipaddress assigned by RAS. if it belongs to its own lease it should run the application otherwise it would be closed.
First we implemented with RAS Dialer Utility but people were able to access application by changing Fone number in the RAS Dial up entry .
we were trying to get some method that application would not be able to run unless pc have an ip of allowed list
 
I had to do this to get active-mode FTP working the other day. The trouble is, I already had a connection to a host over RAS so it was straightforward to check the Sockets LocalEndPoint property.

Perhaps you could do something like that if you find no other way.
 
Sorry, I didnt understand your answers,guys.
Is there a way to get only one IPaddress in a list of IPaddresses?
Maybe Some thing like:

host.AddressList.ByName(PPP); ?

What is RAS?
 
Well thats strange coz in case we develop our own RAS (Remote Access Server) dial up utility then with that we can get IP address assigned by RAS.
but this is entirely different case, our system is already connected to 2 different netowrks 1, local and second is assigned by Remote access server.
on every PC it;s first preority is toward its local netowrk that;s why when we try to get Ip addresses it shows first IP address assigned to network card. and after that some external.
 
I cant say exectly about that. if your Network Card has 2 IP then the 2nd one would also be its other Ip address assigned to netowrk card, and at the end it would be PPP address
I think at the end of search it shows the PPP IP.
 
I did mistake

I have checked and confirmed. the code you have written

Code:
using System;
using System.Net;

    static void Main(string[] args) {
      string machine_name = Dns.GetHostName();
      IPHostEntry host = Dns.GetHostByName(machine_name);

      for (int i=0; i < host.AddressList.Length; i++){
        Console.WriteLine(host.AddressList[i]);
      }
      Console.ReadLine();
    }

And it gave me this Result

192.168.0.2
202.154.239.40
192.168.0.31

in these results

First one was ip assigned to my network card
Second one was PPP ip
and the last one was the another Ip address assigned to my Netowrk Card

I hope now it would be clear that the 2nd Entry is PPP dial Up.

Can any one explain, In which Sequence a System Saves it;s IP entries ?
 
The 2nd Entry is PPP dial Up only if there are more then 1 IPaddresses?
What if there are more then 3,4 or 4?
We need to get a better understanding about it.
Isnt there any property that holds a string that contains the name or describes the IPaddress
 
Back
Top