Can Angular ping local addresses in a manner similar to using the terminal?

Looking for a way to ping devices on my local network, similar to using the ping command in the terminal to ping the router or any connected devices. I've figured out how to ping servers like google.com, but it doesn't seem to work with local addresses. Is it even possible? Below is my typescript code:


private source = interval(3000);

  constructor(private _http: HttpClient) { }

...


getStatutDevice(ip: string){

    //IP Value look like "192.168.1.20" for example

    this.source.subscribe(() => {
      this._http.get(ip, { observe: 'response' })
        .pipe(first())
        .subscribe(resp => {
          if (resp.status === 200 ) {
            console.log(true);
          } else {
            console.log(false);
          }
        }, err => console.log(err));
    });
}

Encountered this error in the console:

zone-evergreen.js:2863 GET http://localhost:4200/192.168.1.20 404 (Not Found)

When I add "https://" before the ip address, I get:

GET net::ERR_CONNECTION_REFUSED

Struggling to decipher these messages and find a solution.

Answer №1

Have you heard of this amazing typescript tool? It allows you to perform a tcp ping.

Answer №2

Performing an ICMP Ping ("similar to using the terminal") is not possible within a web browser. Any effort to do so will result in either tcp or http get requests.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for expanding third-party classes in a versatile manner using Typescript

tl;dr: Seeking a better way to extend 3rd-party lib's class in JavaScript. Imagine having a library that defines a basic entity called Animal: class Animal { type: string; } Now, you want to create specific instances like a dog and a cat: const ...

Variables within Angular2 services are resetting when the route changes

I have been utilizing a service to monitor the status of my model. I have several components that need to access the variables and properties of this service. The issue arises when the first component initializes, sets the model, but upon trying to access ...

angular clear transition state post animation

Recently, I've been working on this code snippet: animations: [ trigger('shake', [transition('* => *', /* some animation */)]) ] In addition to that, I have this piece of code: <app-button [@shake]="shake" > & ...

Differences in Angular 2 Performance: Analyzing AOT and JIT Payloads

I'm still getting the hang of Angular 2, so feel free to correct me if I'm off base. Comparing Angular 1 and 2 in terms of the compiler: In Angular 1, the compiler is more general and dynamic, meaning that a single code is used for dirty checki ...

Angular 7 - ALERT: Circular dependency identified:

Suddenly, a lightbulb went off in my head. I encountered two warnings while running ng serve: WARNING in Circular dependency detected: src\app\_services\ignore-interceptor.service.ts -> src\app\_services\index.ts -> sr ...

Implementing JavaScript Code in TypeScript

Every JavaScript code should also be valid in TypeScript, but when attempting to run the following code snippet below, an error is triggered. Could someone convert this JavaScript code into TypeScript? Error: 20:9 - TS2531 Error: Object is possibly 'z ...

Angular - The parameter type '(error: any) => void' cannot be assigned to the type '() => void'

I encountered an issue with my error handling code in Angular-11: return this.api.post('auth/user/login', data, headers).subscribe( (result: any) => { console.log(result.message); console.log(result.code); if ...

ngx-charts - Horizontal Bar Charts dynamically adjust bar thickness when data is updated

Using Angular and ngx-charts to display data fetched from the server works perfectly on initial load trigger with the ngOnInit() method calling getStats() function. Everything loads as expected: https://i.sstatic.net/8OsbD.png However, upon clicking the ...

Retrieve data from a web api at regular intervals using Angular observables and subscription

My Launch method is designed to start an engine by taking parameters and returning the instance name once started. After that, I need to periodically query another service every 2 seconds to check if the status has changed to either "Succeeded" or "Faile ...

The importance of handling undefined values in TypeScript and React

There is a condition under which the IconButton element is displayed: {value.content && <IconButton aria-label="copy" onClick={() => copyContent(value.content)}> <ContentCopy /> </IconButton> } However, a ...

Can you tell me if it's a problem that I can view the application structure from the console's source window?

I have been asking around trying to find the answer to the question "what are the implications of being able to see the project structure in the source window of a browser?". Unfortunately, I have not received a satisfactory response yet, which is why I am ...

Error in Electron: Uncaught TypeError - Attempting to assign a value to an undefined property 'title'

Currently, I am in the process of creating some classes for my code using TypeScript, Material UI, React, and Electron. Everything seems to be running smoothly when tested on CodeSandbox. However, when I try to run the code in the Electron environment, all ...

Angular: Step-by-step guide to controlling input field visibility with a toggle switch

// The property autoGenerate is declared in my .ts file autoGenerate: boolean; constructor(){ this.autoGenerate = true; } <div class="col-sm-4"> <div class="checkbox switcher"> <label>Invoice Number * <input t ...

Having trouble integrating jQuery into an Angular CLI project

I'm trying to incorporate jQuery into my angular project created with angular cli. I followed the instructions provided on this website: To begin, I installed jQuery by running: npm install --save jquery; Next, I added type definitions for jQ ...

Can you determine the size of an unknown array in TypeScript?

Currently diving into TypeScript and tackling some TDD challenges. Within my model file, I'm working with a property named 'innovatorQuotes' that should be an array containing strings with a fixed length of 3. I'm struggling to nail dow ...

Implementing Service Communication

I created an Angular Application using the Visual Studio Template. The structure of the application is as follows: /Clientapp ./app/app.module.shared.ts ./app/app.module.client.ts ./app/app.module.server.ts ./components/* ./services/person-data.service. ...

Is it possible to effectively iterate through an Angular service request?

Can you help me troubleshoot this code to ensure it runs smoothly? onSubmit() { let pdfData = [ { field_name: 'data.Date', value: this.freshDeskData.date, placeholder: '', page_no: 1, }, ...

Include module A in module B, even though module A has already included module B's Angular

Currently, I am facing an issue with circular dependencies between two modules - User and Product. The User Module has already imported the Product Module to utilize the ProductListComponent. Now, I need to import/use the UserListComponent from the User Mo ...

Exploring intricate JSON data in Angular 4 applications

Below is the json structure I have: [ { "section":{ "secName":"Module 1", "pages":[ { "pageName":"Page 1", "pageType":"brightcove", "pageData":[ { ...

Using Owl Carousel 2 and other jQuery plugins in Angular 4 TypeScript classes: A step-by-step guide

I have been facing challenges trying to incorporate jQuery plugins into an Angular 4 TypeScript class. Despite multiple attempts, I have not been able to achieve my goal. I tried various methods, but the HTML component view in Angular 4 does not seem to s ...