|
-
Jul 19th, 2009, 02:41 AM
#1
Thread Starter
Frenzied Member
TCP issue with IP
I've made a small communication channel with other users of my application, it will connect using TCP which I tested and worked with two instances of my application on my home PC.
I have to type in my IP address of what would be the "remote" computer i'm talking to, my issue is some of my users may not even know what their IP is to give it to me so how can I get my IP and save it as a setting to send to other users so it can be added as the PC they are talking to?
-
Jul 19th, 2009, 09:48 AM
#2
Re: TCP issue with IP
There are a lot of websites out there that let you lookup your IP. Many of them have an automated page that simply returns the IP address as the whole contents of the page. You'll need to use something like that and connect with a webclient and pull that infomration down.
-
Jul 19th, 2009, 03:45 PM
#3
Thread Starter
Frenzied Member
Re: TCP issue with IP
Surely there is an easier way than this, it must on stored on my PC somewhere?
I can get it from command prompt can't i? so how does that work?
-
Jul 19th, 2009, 03:53 PM
#4
Re: TCP issue with IP
The "external" IP is not stored on the computer, because it is not directly tied to the computer as such. A computer can have one or more network cards, these network cards can have local IPs assigned to them. Your gateway to the internet though, such as your router, is assigned an external IP. Your computer is not assigned an external IP.
-
Jul 20th, 2009, 02:16 AM
#5
Thread Starter
Frenzied Member
Re: TCP issue with IP
Yeah I thought so, I know there is a command you can put into command prompt to get it so if this is the case couldn't there be a funtion in VB which would do the same thing?
Any ideas?
-
Jul 20th, 2009, 04:50 AM
#6
Lively Member
Re: TCP issue with IP
Is this what you are looking for?
Display the IP address using WMI
vb Code:
Private Sub Form_Load()
'add a reference to the Microsoft WMI Scripting 1.2 library
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration", , 48)
For Each objItem In colItems
'Form1.Print "IPAddress: " & objItem.IPAddress
console.writeline("IPAddress: " & objItem.IPAddress)
Next
End Sub
---------------------------------------------------
noob coder
---------------------------------------------------
-
Jul 20th, 2009, 05:14 AM
#7
Re: TCP issue with IP
You can get your local IP via IPCONFIG at the command line but as others have stated, this is no use for people external to your network as they can only see your external IP which is not stored on your PC anywhere. Your PC has no idea that it has an external IP address, it is your router/modem that actually uses your external IP as Athiest has already explained and unless your router supports some method of retrieving the IP currently assigned to its external interface via some command line interface or something like that then there is no easy way of getting this without using one of those websites like www.whatismyip.com.
The code that heeroyu16 posted will just get your internal IP address, which is not what you want. I also must point out that the code heeroyu16 has provided looks more like a vbscript example than a VB.NET example (and uses the On Error Resume Next statement that many people detest, as it basically just hides errors from you so you cant see why something isnt working)
-
Jul 20th, 2009, 11:49 AM
#8
Fanatic Member
Re: TCP issue with IP
Why does it matter what it looks like?
It's WMI...
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 20th, 2009, 12:10 PM
#9
Re: TCP issue with IP
What do you mean why does it matter what it looks like? This is a VB.NET forum so do you think posting examples that use vbscript style code is a good idea? and what has it being WMI got to do with anything :S
-
Jul 20th, 2009, 12:19 PM
#10
Fanatic Member
Re: TCP issue with IP
Well, WMI is pertinent to any .NET language.
We don't have a WMI area, so posting it here is the only place it can be posted.
And, if it answers his question, just because it isn't VB.NET doesn't mean an answer isn't relevent.
He is using VB.NET so is asking his question here. Just because the solution isn't VB.NET doesn't mean a post/thread isn't in the right spot.
It matters what language the question is originating from whether or not the thread is in the right spot.
You do know what WMI is right?
Last edited by Seraph; Jul 20th, 2009 at 12:24 PM.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 20th, 2009, 12:28 PM
#11
Re: TCP issue with IP
Yes I know what WMI is... I am confused by your post though. I was not suggesting that the original poster had created this thread in the wrong section, I was just saying that the example code that heeroyu16 posted was not very .NET and as you have pointed out, the original question is regarding a .NET app.
If the original creator of this thread sees that example code and knows how to use WMI in .NET and also knows that the example code is not very good practice in a .NET program the fine... but dont you think they are quite big assumptions? I cant believe you are arguing about this when the code example is not even anything like what the OP actually needs anyway - he wants his external IP and that WMI example just gets your internal IPs. You do know what an IP address is right?
-
Jul 20th, 2009, 12:39 PM
#12
Fanatic Member
Re: TCP issue with IP
I wasn't being sarcastic, I was just making sure you knew what WMI was.
I didn't read the code, I was just talking about the general assumption you made that because it looks like VBS that it shouldn't be in here.
I've had a couple of my posts answered with WMI code when I was wondering if there was a way to do it in VB.NET.
From there, I went on to learn what WMI was and how to implement it since that was the answer and there was no answer in VB.NET.
If WMI is the answer (whether the above post is or isn't the solution) it should still be considered, whether it looks like VB Script or not (and whether the person's coding style is up to par with a professional or not; I'm not a professional programmer and my solution may work but not be accepted "standard" but doesn't mean it's totally wrong.). It's part of the learning process. If the OP doesn't understand WMI, then he will ask how to implement it or look it up on his own.
If we were to assume he doesn't know anything about coding, every post would have to be a step-by-step tutorial on how to implement the solution so that we don't miss anything, just in-case he doesn't kow what we are talking about.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jul 20th, 2009, 12:41 PM
#13
Re: TCP issue with IP
OK thats fair enough but I fail to see at what point I said anything like "that is not the solution because it looks like vbscript". Read my original post again (no I havent edited it), I was simply pointing it out so that the OP didnt think that was the standard way of using WMI in .NET thats all.
-
Jul 20th, 2009, 12:46 PM
#14
-
Jul 20th, 2009, 12:48 PM
#15
Re: TCP issue with IP
lol no worries
-
Jul 20th, 2009, 10:10 PM
#16
Lively Member
Re: TCP issue with IP
shucks just noticed he need external ips.... (i'm blind~~~)
true enough I did not read in depth of what he wants...
Well it is an old sample to get you started using wmi is one way of getting own ip. which i coded years ago.
the on error then go to next is an old method of handling errors, if want change it to a try catch ( mostly I use it only for debugging) or for an even better handling if else statement if you understand what error you will get.
in asp i use this to obtain client's ip... i wonder if this is available in vb.net....?
Request.UserHostAddress()
Request.UserHostName()
or use System.Net.WebClient to http://whatismyip.com/automation/n09230945.asp to obtain the external ip.....
Last edited by heeroyu16; Jul 20th, 2009 at 10:37 PM.
---------------------------------------------------
noob coder
---------------------------------------------------
-
Jul 21st, 2009, 01:26 AM
#17
Thread Starter
Frenzied Member
Re: TCP issue with IP
So in a nutshell I should call a script on a webserver get this to return my IP address and save it. Like a webservice?
OR
If I had a very simple page which displayed my IP like the link in post 16, so i called a webpage could I somehow read the output to get the IP?
-
Jul 21st, 2009, 01:37 AM
#18
Re: TCP issue with IP
Yeah, the page that heeroyu16 linked to in post #16 returns nothing but the IP, so you could do something as simple as:
Code:
Dim ip As String
Using client As New System.Net.WebClient
ip = client.DownloadString("http://whatismyip.com/automation/n09230945.asp")
End Using
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|