none
How to get IP-adress? RRS feed

  • Question

  • Hey guys!

    I would like to know how to get the IP-adress of the current computer and how to send this one to another computer.

    I want to program a chatprogramm for my game. So I need this. If you know a function which do this tell me this please.

    Thanks!


    Greetings Timo

    Monday, October 1, 2012 4:19 PM

Answers

  • Sup Timo!

    There are a couple of site links which display the IP of a computer which has accessed it!

    So I used SB's Network.GetWebPageContents() to access them. Then, made some sanitation of the content to remove any possible characters which are neither a digit nor a period as precaution! However, most sites didn't need that. :D

    So, here's the code:

    '_____________________________________________'
    ' My WAN IP
    ' by GoToLoop (2012/Oct)

    ' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
    '/thread/c77b6990-52c6-4cbe-9b2b-ab8a069e3ea1
    '_____________________________________________'
    InitVars()
    GetURLList()

    site = url[6]
    IP = Network.GetWebPageContents(site)
    Sanitize()

    TextWindow.WriteLine(IP)
    '_____________________________________________'
    Sub Sanitize
     
      IPExtract = ""
     
      While IP <> ""
        
        char = Text.GetSubText(IP  1,1)
        IP = Text.GetSubTextToEnd(IP, 2)
        
        If Array.ContainsValue(valid, char) Then
          IPExtract = Text.Append(IPExtract, char)
        EndIf
        
      EndWhile
     
      IP = IPExtract
     
    EndSub
    '_____________________________________________'
    Sub InitVars
     
      For char = 0 To 9
        valid[char] = char
      EndFor
     
      valid[10] = "."
     
    EndSub
    '_____________________________________________'
    Sub GetURLList
     
      url[1] = "http://ip.appspot.com/"
      url[2] = "http://loopware.com/ip.php"
      url[3] = "http://icanhazip.com/"
      url[4] = "http://sputnick-area.net/ip"
      url[5] = "http://cfaj.freeshell.org/ipaddr.cgi"
      url[6] = "http://checkip.dyndns.org/"
     
    EndSub
    '_____________________________________________'

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    • Edited by GoToLoopEditor Tuesday, October 2, 2012 7:22 AM
    • Marked as answer by Timo Sö Thursday, October 4, 2012 9:18 PM
    Tuesday, October 2, 2012 7:15 AM
    Answerer

All replies

  • I would recommend using the Data Extension. Unfortunately, there is a bug in the client-server part of the extension, but NetworkPlus can get your IP.

    Email me at gungan37 at gmail dot com if you would like an old Data Extension version and Small Basic 0.9 (that have a working NetworkClient and NetworkServer). This might be against Oskariok's license for the extension, though, so best to ask his permission.

    Monday, October 1, 2012 11:55 PM
    Answerer
  • Sup Timo!

    There are a couple of site links which display the IP of a computer which has accessed it!

    So I used SB's Network.GetWebPageContents() to access them. Then, made some sanitation of the content to remove any possible characters which are neither a digit nor a period as precaution! However, most sites didn't need that. :D

    So, here's the code:

    '_____________________________________________'
    ' My WAN IP
    ' by GoToLoop (2012/Oct)

    ' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
    '/thread/c77b6990-52c6-4cbe-9b2b-ab8a069e3ea1
    '_____________________________________________'
    InitVars()
    GetURLList()

    site = url[6]
    IP = Network.GetWebPageContents(site)
    Sanitize()

    TextWindow.WriteLine(IP)
    '_____________________________________________'
    Sub Sanitize
     
      IPExtract = ""
     
      While IP <> ""
        
        char = Text.GetSubText(IP  1,1)
        IP = Text.GetSubTextToEnd(IP, 2)
        
        If Array.ContainsValue(valid, char) Then
          IPExtract = Text.Append(IPExtract, char)
        EndIf
        
      EndWhile
     
      IP = IPExtract
     
    EndSub
    '_____________________________________________'
    Sub InitVars
     
      For char = 0 To 9
        valid[char] = char
      EndFor
     
      valid[10] = "."
     
    EndSub
    '_____________________________________________'
    Sub GetURLList
     
      url[1] = "http://ip.appspot.com/"
      url[2] = "http://loopware.com/ip.php"
      url[3] = "http://icanhazip.com/"
      url[4] = "http://sputnick-area.net/ip"
      url[5] = "http://cfaj.freeshell.org/ipaddr.cgi"
      url[6] = "http://checkip.dyndns.org/"
     
    EndSub
    '_____________________________________________'

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    • Edited by GoToLoopEditor Tuesday, October 2, 2012 7:22 AM
    • Marked as answer by Timo Sö Thursday, October 4, 2012 9:18 PM
    Tuesday, October 2, 2012 7:15 AM
    Answerer
  • @gungan37

    I think you mean "NetworkPlus.IsIPAddress("a specified text")" . But I can't see my current IP with this task. I must use version 1.0, because I need some special tasks of version 1.0 and some other extensions of 1.0. But thanks very much.

    @GoToLoop

    This looks very well! And it works good too! If I get your permission, would I use this code as a kind of subprogram for my chat program. U would get full credit. :D


    Greetings Timo

    Tuesday, October 2, 2012 2:21 PM
  • As I declared in this forum before:

    If not stated otherwise, all of my programs and snippets here are freely given to be used, copied and studied as any1 please!

    Consider them as a permissive software license or something like that!  :P


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Tuesday, October 2, 2012 2:56 PM
    Answerer
  • I will consider it as GoToLoop work. :P

    Thanks.


    Greetings Timo

    Tuesday, October 2, 2012 3:42 PM
  • As I declared in this forum before:

    If not stated otherwise, all of my programs and snippets here are freely given to be used, copied and studied as any1 please!

    Consider them as a permissive software license or something like that!  :P


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    GoToLoop,

    You've made a lot of great contributions in this forum.

    Please email me. It's edprice at Microsoft.

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Thursday, October 11, 2012 4:57 AM
    Owner
  • Already did. Just dunno if I got it right. Is that microsoft.com or just microsoft?  @_@

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Thursday, October 11, 2012 5:37 AM
    Answerer