How to get IP Address in asp.net using vb.net

Hai All

How to get Ip address in asp.net using vb.net. 

any one please help me....Its urgent for my project

Thanks in Advance

0
soori457
2/2/2009 10:51:59 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

25 Replies
841 Views

Similar Articles

[PageSpeed] 27

Request.Servervariables("REMOTE_ADDR")

For example, create a label called Label2 and post the following code in page_load:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.Label2.Text = Request.ServerVariables("REMOTE_ADDR")
    End Sub
However take notice that it's the IP adress of the server. 

Also look at: http://forums.asp.net/t/892765.aspx

 

Cheers Danny Schouren

0
dannx1986
2/2/2009 12:04:39 PM

soori457:

Hai All

How to get Ip address in asp.net using vb.net. 

any one please help me....Its urgent for my project

Thanks in Advance

refer here

http://forums.asp.net/p/1360555/2807643.aspx#2807643


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
2/2/2009 12:13:44 PM

 Thanks for your replies.

I used the code

IPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

If IPAddress = "" Then

IPAddress = Request.ServerVariables("REMOTE_ADDR")

But its not giving me the exact ip address.

 The output I got by using the above code is 127.0.0.1  . But thats not the exact ip of my system

 

 

0
soori457
2/2/2009 12:26:03 PM

 hi soori457,

go through the following links, those may help you.

link1

link2


Regards,
Ravi Kishore.Ch

Mark as "ANSWER" if you got the solution from this post.
0
chravikishore
2/2/2009 12:28:37 PM

soori457:

Thanks for your replies.

I used the code

IPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")

If IPAddress = "" Then

IPAddress = Request.ServerVariables("REMOTE_ADDR")

But its not giving me the exact ip address.

 The output I got by using the above code is 127.0.0.1  . But thats not the exact ip of my system

Thats bcoz ur server and client are same machine you will get the exact IP Address when you access the site from some other machine


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
2/2/2009 12:46:46 PM

Hi

Request.ServerVariables ["REMOTE_ADDR"]

Best Regards..


TUFAN01MAN
0
TUFAN01MAN
2/2/2009 12:48:05 PM

 still am getting 127.0.0.1 only

Actually I'm developing an intranet application. What i need is, I have to pass a message from server to another pc over the network when there is an ocassion..

 any one solve this please...

0
soori457
2/2/2009 12:57:05 PM

soori457:

 still am getting 127.0.0.1 only

Actually I'm developing an intranet application. What i need is, I have to pass a message from server to another pc over the network when there is an ocassion..

 any one solve this please..

This is meant for public ips in instranet all machines have same public IP hence you will have to do this way

http://www.devasp.net/net/articles/display/686.html


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
2/2/2009 1:04:14 PM

 Thanks Mr. Mudassarkhan.

I tried  it, but I'm getting 127.0.0.1 only.

I found this code

        Dim strHostName As String = System.Net.Dns.GetHostName()
        Dim clientIPAddress As String = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString
        TextBox1.Text = clientIPAddress.ToString

 This is working.

Now tell me, How to pass message from one pc to another pc over the network

 

0
soori457
2/2/2009 1:38:55 PM

You can try Net send ..... but it doesn't work with Windows Vista.


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Shell("net send " & TextBox1.Text & "Here comes your message!!!!")
    End Sub

Cheers Danny Schouren

(ps: the messenger service needs to be running)

0
dannx1986
2/2/2009 2:32:13 PM

soori457:

Thanks Mr. Mudassarkhan.

I tried  it, but I'm getting 127.0.0.1 only.

I found this code

        Dim strHostName As String = System.Net.Dns.GetHostName()
        Dim clientIPAddress As String = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString
        TextBox1.Text = clientIPAddress.ToString

 This is working.

Now tell me, How to pass message from one pc to another pc over the network

http://www.codeproject.com/KB/IP/ChatMasala.aspx

http://www.programmersheaven.com/mb/embedded/277631/277631/lan-chat-utility-available-with-full-source-code-v30/?S=B20000


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
2/2/2009 3:10:00 PM

 Thanks Danny for ur reply. I tried that command in command prompt. But I'm getting error. once check my command.

net send system1 "Hello"

This is Error am getting, once check it please

Error 

 

0
soori457
2/3/2009 9:37:20 AM

Try withoud the ""'s

net send system1 Hello (also try to replace system1 with IP adres)

This should work if messenger service is running (on both computers client/server)

Greetings

0
dannx1986
2/3/2009 10:15:31 AM

 I removed the ""s, and messenger service is ruunning on, then also its not working. can I send message to my system using the same command

0
soori457
2/3/2009 10:23:06 AM

did you visit the link I suggested??


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
2/3/2009 10:30:18 AM

Yes you can, youse your own ip or computername.

Try running it from command window... start > run > cmd

Also check if net.exe exists in C:\Windows\system32\net.exe

0
dannx1986
2/3/2009 10:41:12 AM

 ya, Thnks. But I dont need chat applucation, I just need to pass a message from one pc to another pc through network

0
soori457
2/3/2009 10:42:25 AM

 ya, net.exe is there. what I'm saying is can I send msg to my system. my system name is system1.

Can I try this

net send system1 hello

in my system only. will it works??

0
soori457
2/3/2009 10:47:44 AM

It should work... it's not a chat app... you can only pass a message...

0
dannx1986
2/3/2009 10:57:20 AM

 I tried

net send system1 hello

The error I'm getting is

An error occurred while sending a message to SYSTEM1
The message alias could not found on the network.
More Help is available by typing NET HELPMSG 2273

can  you tell me, wts the problem

0
soori457
2/3/2009 11:21:08 AM

This is the exact error I get when i stop the messenger service.

start > run > services.msc > messenger > start

Mabey try another system. ( is your computer sp2? http://support.microsoft.com/kb/839018 )

Try search Google... if it doesn't work mabey it's not the effort, and try other way of messaging.
Course Net send messenger service is normally stopped with SP2 I believe... so I don't know how much computers you are going to send messages to.

Hope it helps

0
dannx1986
2/3/2009 11:34:23 AM

 Ya, my os is windows xp version 2002 sp2

Is there any other way??

0
soori457
2/3/2009 11:48:34 AM

Don't really know...

Try Google, I found http://forums.asp.net/t/1372724.aspx

Do you need to implement it inside a webpage?

(still strange net send doesn't work Huh? It was the way of communicating/annoying other classmates a few years ago Embarrassed)

0
dannx1986
2/3/2009 12:02:12 PM

 Thanks for your Information Mr.Danny

I'm very new to Asp.Net, with your information, I gain some knowledge. 

Thank you so much

0
soori457
2/3/2009 12:18:29 PM

soori457:

 I removed the ""s, and messenger service is ruunning on, then also its not working. can I send message to my system using the same command

Hi soori457,

Please take time to read mudassarkhan's replied.

Please post your code for us checking if the issure still here.

By the way, please tell us your test environment.


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
2/5/2009 6:59:09 AM
Reply: