Results 1 to 1 of 1

Thread: [RESOLVED] Convert Python "GET" Statement to VB.NET

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    295

    Resolved [RESOLVED] Convert Python "GET" Statement to VB.NET

    Here is the answer to my question..



    Code:
            Dim webClient As WebClient = New WebClient()
            webClient.QueryString.Add("api_key", apiKey)
            webClient.QueryString.Add("ip", hostName)
            Dim result As String = webClient.DownloadString(requestUrl)
    
    
            Return result

    Thanks all.




    Hello All,

    It's been a long time since I've visited the Forums, I hope all have been well.

    If someone could, would you be able to help me re-code a simple Python GET statement to VB.Net. I am having all sorts of issues trying to figure out Webrequest. I've never had to use it before. I'm not even sure if that's the way to go for this issue.

    Thank you in advance,

    -Ron

    Here is the code I'm using and I am erroring out on the response from the server.

    Error ==> The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

    Here is my code..

    Code:
        Private Sub AnalysIPUsingMalwarecomToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AnalysIPUsingMalwarecomToolStripMenuItem.Click
            'Get the IP Address
            Column = 4
            Row = EstablishedConDGV.CurrentCell.RowIndex
            Dim ForeignAdd As String
            ForeignAdd = EstablishedConDGV(Column, Row).FormattedValue.ToString
    
            ForeignAdd = "73.178.116.141"
            'ForeignAdd = "c-73-178-116-141.hsd1.nj.comcast.net"
            Dim APIKey As String = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            Dim Malware As String = "https://public.api.malwares.com/v3/ip/info"
            Dim ReturnedData As String = GetJsonResponse(APIKey, ForeignAdd, Malware)
    
    
    
            MessageBox.Show(ReturnedData)
        End Sub

    Code:
        Public Function GetJsonResponse(apiKey As String, hostName As String, requestUrl As String) As String
            Dim request = System.Net.HttpWebRequest.CreateHttp(requestUrl)
    
            'these are the basic required configuration elements
            request.Headers.Item("api_key") = apiKey
            request.Host = hostName
            request.Method = Net.WebRequestMethods.Http.Get
            request.ContentType = "application/json"
    
            'This gets the body of the response
            Using response = request.GetResponse()
                Using reader As New IO.StreamReader(response.GetResponseStream)
                    Return reader.ReadToEnd
                End Using
            End Using
        End Function
    Here is the Python Statement..

    Code:
    import requests 
    params = {'api_key': 'API KEY', 'hostname': 'www.malwares.com'}
    response = requests.get('https://public.api.malwares.com/v3/hostname/info', params=params)
    json_response = response.json()
    Here is the JSON Used...

    Code:
    {
      "result_code": "Result Code (Number)",
      "result_msg": "Result Message (String)",
      "version": "API PAGE VERSION (String)",
      "date": "API Request Time (String)",
      "hostname": "Hostname to check (String)",
      "view_count": "Hostname Search Count (Number)",
      "whois": "Hostname Whois search information (String)",
      "location": [{
        "cc" : "country code (String)",
        "cname" : "country name (String)",
        "city" : "city name (String)",
        "longitude" : "longitude (String)",
        "latitude" : "latitude (String)",
        "iplist" : "related IP list (Array)"
      }],
      "ip_history": {
        "total" : "IP number used the concerned Hostname (Number)",
        "list" : "IP list used the concerned Hostname (Array)"
      },
      "detected_url": {
        "total" : "malicious URL number which used the concerned Hostname (Number)",
        "list" : "malicious URL list which used the concerned Hostname (Array)"
      },
      "undetected_url": {
        "total" : "Normal URL number which used the concerned Hostname (Number)",
        "list" : "Normal URL list which used the concerned Hostname (Array)"
      },
      "detected_downloaded_file": {
        "total" : "malicious file number downloaded from the concerned Hostname (Number)",
        "list" : "malicious file list downloaded from the concerned Hostname (Array)"
      },
      "undetected_downloaded_file": {
        "total" : "normal file number downloaded from the concerned Hostname (Number)",
        "list" : "normal file list downloaded from the concerned Hostname (Array)"
      },
      "detected_communicating_file": {
        "total" : "malicious file number communicated with the concerned Hostname (Number)",
        "list" : "malicious file list communicated with the concerned Hostname (Array)"
      },
      "undetected_communicating_file": {
        "total" : "normal file number communicated with the concerned Hostname (Number)",
        "list" : "normal file list communicated with the concerned Hostname (Array)"
      }
    }
    Last edited by NJDevils28; Aug 17th, 2018 at 02:34 PM.
    Lo And Behold
    This is my first Microsoft App Submission
    Your opinion of it would be appreciated

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