vb.net - Getting External IP -
i'm trying external ip of user, can save user file. can't find way it. i've tried doing:
private function getexternalip() net.ipaddress     using wc new net.webclient         return net.ipaddress.parse(encoding.ascii.getstring(wc.downloaddata("http://whatismyip.com/automation/n09230945.asp")))     end using end function   but keep getting formatexception saying "ip invalid"
here code, may want add check ensure not run often:
 private shared function getexternalip() string      dim response string = string.empty      try          dim mywebclient new system.net.webclient         dim whatismyip string = "http://automation.whatismyip.com/n09230945.asp"         dim file new system.io.streamreader(mywebclient.openread(whatismyip))          response = file.readtoend()         file.close()         file.dispose()         mywebclient.dispose()      catch ex exception         response = "could not confirm external ip address" & vbcrlf & ex.message.tostring     end try      return response  end function      
Comments
Post a Comment