Hack Forums
[.NET] [Function] Skype-Name? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [Function] Skype-Name? (/showthread.php?tid=4472777)



[Function] Skype-Name? - Giommi - Oct 2, 2014

hi there
a little snipped to check if skype exist, not used or invalid

Code
Private Function GetPageSource(ByVal URL As String)
      Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(URL)
      Dim response As System.Net.HttpWebResponse = request.GetResponse()
      Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
      Dim sourcecode As String = sr.ReadToEnd()
      Return sourcecode
    End Function

Private Function CheckSkype(ByVal Skypename As String)
      Dim t As String = GetPageSource("https://login.skype.com/json/validator?new_username=" & Skypename)
      If t.Contains("status"":200") Then
      Return "error" 'not used skype name
      ElseIf t.Contains("status"":406") And Not t.Contains("Invalid Skype Name.") Then
      Return "exist" 'existing skype name
      ElseIf t.Contains("status"":406") And t.Contains("Invalid Skype Name.") Then
      Return "error2" 'invalid skype name
      End If
    End Function



* - Earn - Oct 2, 2014

This is a nice share, but there are a few ways that you can make it better. The first tip is, what is GetPageSource? I am assuming that it is another function, that isn't posted, that is a WebClient that gets the source of the page. It isn't needed. Another thing is that there is no Error Handling.

Here is how I would go about it.
Code
Private Function CheckSkype(ByVal Skype As String)
      Try
      Using WC As New Net.WebClient
            Dim Src As String = WC.DownloadString("https://login.skype.com/json/validator?new_username=" & Skype)
            If Src.Contains("status"":200") Then
            Return "Available"
            ElseIf Src.Contains("status"":406") And Not Src.Contains("Invalid Skype Name.") Then
            Return "Not Available"
            ElseIf Src.Contains("status"":406") And Src.Contains("Invalid Skype Name.") Then
            Return "Invalid"
            End If
      End Using
      Catch ex As Exception
      Return "Error: " & ex.ToString
      End Try
    End Function

Please note that I haven't tried this code, but I am pretty sure that it will work.


* - TheBarret - Oct 2, 2014

Why not extract the webheaders from a webrequest?

http://msdn.microsoft.com/en-us/library/system.net.webclient.responseheaders(v=vs.110).aspx


* - PatientZero - Oct 3, 2014

This is a great function,
However I believe it needs a little patching up in places.

Thanks for the share.


* - TheBarret - Oct 3, 2014

(Oct 3, 2014 09:01 AM)PatientZero Wrote:  This is a great function,
However I believe it needs a little patching up in places.

Thanks for the share.

A little? 🤣 i would say from scratch.


* - Giommi - Oct 3, 2014

whoops sry i forgot to post my GetPageSource function :D
sorry i got it in the Function Region


* - PatientZero - Oct 3, 2014

(Oct 3, 2014 09:13 AM)TheBarret Wrote:  A little? 🤣 i would say from scratch.

It's alright,
It can do the job at least :P