Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

92
LINES

< > BotCompany Repo | #1015939 // PC Awareness [Include]

JavaX fragment (include)

!include #1005410 // Cross-Platform Awareness Include

answer {
  if "are you aware"
    ret "i am aware";
  if "Ping"
    ret "pong";
  /*if "say in english *" {
    thread "Speaking" {
      androidSayInEnglish(m.unq(0));
    }
    ret "OK";
  }
  if "say in english now *" {
    androidSayInEnglish(m.unq(0));
    ret "OK";
  }*/
  try answer fileOpBot(s);
    
  if "please eval java *"
    ret "ok " + structure(evalJava($1));
  if "please eval java fresh *"
    ret "ok " + structure(evalJavaFresh($1));
    
  if "list other pcs"
    ret structure(otherPCs());
    
  try answer awarenessBot(s);
  try answer clipboardBot(s);
  try answer screenshotBot(s);
    
  //try answer proxyBot(s);
}



sbool validPeer(MachineInfo info) {
  if (!info.aware || info.computerID == null) false;
  if (info.lastChecked < now()-l(pinging)*pingLoopInterval*2*1000) false;
  true;
}

sS osName(MachineInfo info) {
  ret contains(info.bots, "Dex Bot.") ? "Android" : info.os;
}

svoid scanSubnet {
  pcall {
    S ip = getMyIP();
    int i = ip.lastIndexOf('.');
    if (i < 0) ret;
    print("Scanning my subnet...");
    for (int n = 1; n <= 255; n++) {
      S peer = substring(ip, 0, i+1) + n;
      scanPeer(peer);
    }
    print("Subnet scanned.");
  }
}

// 255 threads :)
svoid scanSubnet_parallel {
  pcall {
    S ip = getMyIP();
    int i = ip.lastIndexOf('.');
    if (i < 0) ret;
    print("Scanning my subnet really quickly...");
    for (int n = 1; n <= 255; n++) {
      fS peer = substring(ip, 0, i+1) + n;
      S msg = "Peer Scan " + peer;
      thread msg { scanPeer(peer); }
    }
  }
}

svoid scanPeer(S peer) {
  pcall {
    if (!pinging.contains(peer)) {
      //print("Trying " + peer);
      if (isAware(peer))
        addPeers(ll(peer));
    }
  }
}

static L<S> otherPCs() {
  new L<S> ips;
  for (final MachineInfo info : findConcepts(MachineInfo, "me", false))
    if (validPeer(info) && neq(osName(info), "Android"))
      ips.add(info.ip);
  ret ips;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015939
Snippet name: PC Awareness [Include]
Eternal ID of this version: #1015939/4
Text MD5: 511832c73f4b2a0c786b6c0e4f244f3a
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-31 23:02:58
Source code size: 2067 bytes / 92 lines
Pitched / IR pitched: No / No
Views / Downloads: 421 / 838
Version history: 3 change(s)
Referenced in: #1005411 - PC Awareness
#1015941 - PC Awareness [Dyn Module, old]
#1019770 - LAN Discovery [discovers other JavaX computers, formerly called "PC Awareness"]