Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
How can get the IP address of these modems and my computer?
Posted
Updated 21-Feb-10 9:16am
v5

I am assuming this device is external to your PC in which case you cannot directly get the IP address, as far as I am aware. Generally when you add devices to a network you assign their IP addresses yourself. In order to communicate between networked devices the device that initiates the connection needs to know the IP address of the destination device in advance.
 
Share this answer
 
Modems generally do not have IP addresses; do you mean NICs on your system?
 
Share this answer
 
i have GPRS modem which has IP address. i need it.Please help me?
 
Share this answer
 
ok what is your solution sir? i need help really help
 
Share this answer
 
yusufkaratoprak wrote:
ok what is your solution sir? i need help really help


I am afraid there is no solution. You can only find the local IP addresses of hosts/devices that are listed in your hosts database. If you want the address of a non-local device then you need to use DNS lookup to find it.
 
Share this answer
 
Thanks your help and gentalman sense. But i find a site: http://whatismyipaddress.com/[^] This site give me my ip number. How can i do that with C#.
 
Share this answer
 
v2
yusufkaratoprak wrote:
This site give me my ip number.


This site receives your IP address when you connect to it; that is how it finds it. Also if the address is publicly registered it can deduce where in the world the IP address is - see the FAQ section on the site as it explains this in greater detail. However if you do not know a device/site's IP address and it does not have a registered name in a DNS lookup somewhere there is no way to find it.
 
Share this answer
 
v3
You may try to send the following AT command to your modem: "AT+CGPADDR=1".

If your modem is connected to COM port (assume to port "COM1"), the code may looks as follows:

// ... don't forget to set up baudrate, parity, etc.
SerialPort port = new SerialPort("COM1");
port.DataReceived += new SerialDataReceivedEventHandler(ProcessReceivedData);

port.Open();
port.Write("AT+CGPADDR=1");


and the SerialDataReceivedEvent handler:

private static void ProcessReceivedData(Object sender, SerialDataReceivedEventArgs e)
{
    SerialPort port = (SerialPort)sender;

    string response = port.ReadExisting();
    Console.WriteLine(response);
}


It should work if your system currently does not use the modem (otherwise, port is busy and you'll get UnauthorizedAccessException).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900