Results 1 to 18 of 18

Thread: TCP issue with IP

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    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?

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    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?

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    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?

  6. #6
    Lively Member heeroyu16's Avatar
    Join Date
    Nov 2005
    Posts
    123

    Re: TCP issue with IP

    Is this what you are looking for?
    Display the IP address using WMI

    vb Code:
    1. Private Sub Form_Load()
    2. 'add a reference to the Microsoft WMI Scripting 1.2 library
    3. On Error Resume Next
    4. strComputer = "."
    5. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    6. Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration", , 48)
    7. For Each objItem In colItems
    8. 'Form1.Print "IPAddress: " & objItem.IPAddress
    9. console.writeline("IPAddress: " & objItem.IPAddress)
    10. Next
    11. End Sub
    ---------------------------------------------------
    noob coder
    ---------------------------------------------------

  7. #7
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #8
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  11. #11
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  12. #12
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  13. #13
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  14. #14
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    Re: TCP issue with IP

    Sorry. Reread it and see that I misread how you were approaching it.

    Friends?

    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]

  15. #15
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: TCP issue with IP

    lol no worries
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  16. #16
    Lively Member heeroyu16's Avatar
    Join Date
    Nov 2005
    Posts
    123

    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
    ---------------------------------------------------

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    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?

  18. #18
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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